physionet
PhysioNet :class:Source — SHA256SUMS.txt-driven, no HTML crawl.
PhysioNetSource
Bases: HTTPSource
A :class:Source for any PhysioNet dataset release.
Inherits all HTTP machinery (client, retry, Range-resume download, checksum verify)
from :class:HTTPSource — it overrides :meth:_list_files (plus its constructor,
which takes a release URL and credentials instead of an explicit URL list). Uses
the SHA256SUMS.txt manifest that every PhysioNet release publishes as the
authoritative file list: each line is <sha256> <rel_path>, and each entry’s URL
is just {base_url}/{rel_path}.
Credential plumbing for restricted datasets (MIMIC-IV, eICU, etc.) is HTTP Basic auth
via the username / password kwargs; open datasets (MIMIC-IV demo) need
neither. Basic auth alone is not sufficient, though: physionet.org serves
credentialed /files/ paths only to clients whose User-Agent starts with
Wget/<version> (their documented bulk-download tool). The gate is a prefix
match — anything appended after the Wget/<version> token is preserved — and it
rejects with a 403 before credentials are considered, with no WWW-Authenticate
challenge, so a wrong UA is otherwise indistinguishable from wrong credentials. To
pass the gate while staying honestly identified, clients built here default to
Wget/<version> MEDS-Extract/<version> (see _default_user_agent); a
user-supplied headers={"User-Agent": ...} wins completely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The PhysioNet release URL, with or without trailing slash — e.g.
|
required |
username
|
str | None
|
PhysioNet username (Basic auth). Omit for open-access datasets. |
None
|
password
|
str | None
|
PhysioNet password. Omit for open-access datasets. |
None
|
client
|
Client | None
|
Optional injected :class: |
None
|
headers, timeout, max_attempts, transport, retry_wait
|
Forwarded to
:meth: |
required | |
include, exclude
|
Optional :mod: |
required | |
unarchive
|
str | None
|
Blanket post-fetch unpack mode applied to every
:class: |
None
|
cleanup_archive
|
bool | None
|
Tri-state controlling per-member archive cleanup after a
successful extraction. |
None
|
Examples:
Public releases (e.g. MIMIC-IV demo) need no auth — construction is eager but
does no network I/O until the manifest is first accessed (:attr:Source.files,
e.g. via :meth:Source.download_all or
:func:~MEDS_extract.download.source.validate_unique_destinations):
>>> src = PhysioNetSource(base_url="https://physionet.org/files/mimic-iv-demo/2.2")
>>> src._base_url
'https://physionet.org/files/mimic-iv-demo/2.2/'
>>> src.close()
The base URL is normalized to end in exactly one trailing slash so URL concatenation is clean — an already-slashed URL passes through unchanged:
>>> with PhysioNetSource(base_url="https://physionet.org/files/mimic-iv-demo/2.2/") as src:
... src._base_url
'https://physionet.org/files/mimic-iv-demo/2.2/'
Credentialed releases (MIMIC-IV, eICU, etc.) take username / password:
>>> src = PhysioNetSource(
... base_url="https://physionet.org/files/mimiciv/3.1",
... username="demo_user", password="demo_pw",
... )
>>> src.close()
Half-credentials are rejected eagerly (better to fail at construction than on first Basic-auth request):
>>> PhysioNetSource(base_url="https://physionet.org/x/1.0", username="u")
Traceback (most recent call last):
...
ValueError: PhysioNetSource: username and password must be supplied together ...
The reversed half — a password without a username — is rejected the same way:
>>> PhysioNetSource(base_url="https://physionet.org/x/1.0", password="p")
Traceback (most recent call last):
...
ValueError: PhysioNetSource: username and password must be supplied together ...
unarchive / cleanup_archive propagate to every
:class:~MEDS_extract.download.source.RemoteFile listed. "auto" is the
expected value for releases that ship archive members alongside non-archive
ones — the unpack only fires for the actual archives:
>>> with PhysioNetSource(
... base_url="https://physionet.org/files/example/1.0",
... unarchive="auto",
... ) as src:
... src._unarchive, src._cleanup_archive
('auto', None)
Source code in MEDS_extract/download/backends/physionet.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
_parse_sha256sums(text)
staticmethod
Parse PhysioNet’s SHA256SUMS.txt format.
Lines look like:
.. code-block:: text
9c3a...f2 subdir/file.csv.gz
abc1...23 README.md
The separator is arbitrary whitespace (two spaces by convention on PhysioNet, but
some manifests use tabs). Blank lines and comment lines (leading #) are
skipped.
Examples:
>>> text = (
... "abc123 foo.csv\n"
... "def456 sub/bar.csv.gz\n"
... )
>>> PhysioNetSource._parse_sha256sums(text)
[{'sha256': 'abc123', 'rel_path': 'foo.csv'}, {'sha256': 'def456', 'rel_path': 'sub/bar.csv.gz'}]
Blank / comment lines are tolerated:
>>> PhysioNetSource._parse_sha256sums("# header\n\nabc x.csv\n")
[{'sha256': 'abc', 'rel_path': 'x.csv'}]
Paths with spaces (rare on PhysioNet but legal) are preserved:
>>> PhysioNetSource._parse_sha256sums("abc folder with spaces/file.txt\n")
[{'sha256': 'abc', 'rel_path': 'folder with spaces/file.txt'}]
Malformed lines raise:
>>> PhysioNetSource._parse_sha256sums("no_separator_on_this_line\n")
Traceback (most recent call last):
...
ValueError: Malformed SHA256SUMS line: 'no_separator_on_this_line'
Source code in MEDS_extract/download/backends/physionet.py
_default_user_agent()
The default User-Agent for :class:PhysioNetSource-built clients.
physionet.org serves credentialed /files/ paths only to clients whose
User-Agent starts with Wget/<version> — a prefix match, with anything appended
after preserved. So the default leads with a Wget/<version> token to pass the
gate, then appends this package’s real identity rather than impersonating wget
outright.
Examples: