@@ -10,12 +10,104 @@ pip install physionet
1010
1111## Usage
1212
13+ ### API Client
14+
15+ Interact with the PhysioNet API to explore and search published projects:
16+
17+ ``` python
18+ from physionet import PhysioNetClient
19+
20+ # Create a client instance
21+ client = PhysioNetClient()
22+
23+ # List all published projects
24+ projects = client.projects.list_published()
25+ print (f " Total projects: { len (projects)} " )
26+
27+ # Display first few projects
28+ for project in projects[:5 ]:
29+ print (f " { project.slug} v { project.version} : { project.title} " )
30+
31+ # Search for projects
32+ ecg_projects = client.projects.search(' ECG' )
33+ print (f " Found { len (ecg_projects)} ECG-related projects " )
34+
35+ # Get all versions of a project
36+ versions = client.projects.list_versions(' mimic-iv-demo' )
37+ for version in versions:
38+ print (f " Version { version.version} : { version.title} " )
39+
40+ # Get detailed information about a specific version
41+ details = client.projects.get_details(' mimic-iv-demo' , ' 2.2' )
42+ print (f " Title: { details.title} " )
43+ print (f " DOI: { details.doi} " )
44+ print (f " Published: { details.publish_datetime} " )
45+ print (f " Size: { details.main_storage_size} bytes " )
46+ ```
47+
48+ ### Authenticated Requests
49+
50+ For endpoints that require authentication (e.g., downloading checksums):
51+
52+ ``` python
53+ from physionet import PhysioNetClient
54+
55+ # Create client with authentication
56+ client = PhysioNetClient(
57+ username = ' your_username' ,
58+ password = ' your_password'
59+ )
60+
61+ # Download checksums file
62+ client.projects.download_checksums(
63+ ' mimic-iv-demo' ,
64+ ' 2.2' ,
65+ ' checksums.txt'
66+ )
67+
68+ # Or use environment variables
69+ # Set PHYSIONET_USERNAME and PHYSIONET_PASSWORD
70+ from physionet.api.utils import get_credentials_from_env
71+
72+ username, password = get_credentials_from_env()
73+ client = PhysioNetClient(username = username, password = password)
74+ ```
75+
76+ ### Using Context Manager
77+
78+ ``` python
79+ from physionet import PhysioNetClient
80+
81+ # Automatically close session when done
82+ with PhysioNetClient() as client:
83+ projects = client.projects.list_published()
84+ print (f " Found { len (projects)} projects " )
85+ ```
86+
87+ ### Utility Functions
88+
89+ ``` python
90+ from physionet.api.utils import format_size
91+
92+ # Format bytes to human-readable size
93+ size = format_size(16224447 )
94+ print (size) # "15.47 MB"
95+ ```
96+
97+ ## Error Handling
98+
1399``` python
14- import physionet as pn
100+ from physionet import PhysioNetClient
101+ from physionet.api.exceptions import NotFoundError, RateLimitError, ForbiddenError
15102
16- # Download a dataset
17- pn.download(' ptbdb' , ' data/ptbdb' )
103+ client = PhysioNetClient()
18104
19- # List all datasets
20- pn.list_datasets()
105+ try :
106+ details = client.projects.get_details(' nonexistent-project' , ' 1.0' )
107+ except NotFoundError:
108+ print (" Project not found" )
109+ except RateLimitError:
110+ print (" Rate limit exceeded, please wait before retrying" )
111+ except ForbiddenError:
112+ print (" Access denied - check credentials or project permissions" )
21113```
0 commit comments