Skip to content

Read WFDB files from explicit HTTP URLs - #817

Merged
tompollard merged 2 commits into
mainfrom
explicit-http-record-paths
Dec 1, 2026
Merged

tompollard merged 2 commits into
mainfrom
explicit-http-record-paths

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Allow explicit HTTP and HTTPS record paths such as wfdb.read_record("https://mirror.example.org/files/mitdb/1.0.0/100"). Header references, signal files, and annotations stay on the named server. This gives custom index servers a single-path alternative to combining set_db_index_url(...), a record name, and pn_dir (#534).

The change uses the existing fsspec HTTP reader. It keeps physionet:// for PhysioNet access with saved credentials, preserves legacy pn_dir behavior, and rejects HTTP write destinations clearly. It does not introduce automatic fallback from a local path to a remote server.

Checks

  • 80 related offline tests passed with the required physionet 0.11.0 dependency, including the existing custom-server tests.
  • 2 localhost HTTP integration tests passed: one reads header, signal, and annotation files with byte ranges; the other follows a multi-segment header reference.
  • Ruff check and format check passed.
  • Sphinx HTML built with warnings as errors.

This is the first step toward retiring pn_dir. A follow-up will add migration warnings and update examples once the explicit URL behavior is reviewed.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, a full URL is a much clearer way to read from a custom server than set_db_index_url plus pn_dir. Reads through read_record, read_signals, read_header and read_annotations work, multi-segment headers follow their segments on the same server, URL plus pn_dir is rejected, and aiohttp is already a core dependency, so a plain install supports this. The offline suite, Ruff and the strict docs build pass locally.

Servers that gzip responses. With the existing DummyHTTPServer(..., allow_gzip=True), reading from the start of 100.dat works, but a partial read deep into the file fails with aiohttp.ClientPayloadError: 400, and a read near the end of a header without a length fails with could not broadcast input array from shape (0,) into shape (10,). fsspec's HTTP reader sends Accept-Encoding: gzip, so the server returns ranges of the compressed body. The _url reader avoids this by sending no Accept-Encoding on range requests. Passing headers={"Accept-Encoding": "identity"} from _fsspec_open for http(s):// paths fixed it in my test (correct size and bytes after a seek). Could you add that, plus a test with allow_gzip=True?

Legacy annotation writer. Record.write, write_record, Record.wrsamp, wfdb.wrsamp, Annotation.write and write_annotations all reject HTTP destinations clearly, but Annotation.wrann(write_dir="https://...") and wfdb.wrann(..., write_dir="https://...") fail with FileNotFoundError: ... 'https://mirror.example.org/files/100.atr'. Calling check_cloud_write(write_dir) there would match. (Nothing is created on disk in any case.)

Optional: a signed URL with a query string (.../100?token=abc) fails with a fsspec glob error, and joining file names onto it would drop the query anyway. A sentence in the docs saying such URLs aren't supported would help.

@tompollard

Copy link
Copy Markdown
Member Author

Good catches. I pushed 23bc015 to address both issues:

  • HTTP reads now request Accept-Encoding: identity, so byte ranges refer to the uncompressed file. I added a test that reads the last frames of a record with no declared length from a gzip-capable server and compares the result with a local read.
  • Annotation.wrann now calls check_cloud_write before processing the annotation. Both it and wfdb.wrann raise the same clear ValueError for HTTP destinations, with a regression test.
  • The custom-server docs now say that URLs with query strings, including signed URLs, are unsupported.

The HTTP tests (11), annotation and cloud-write tests (195), Ruff, and the strict docs build pass locally.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, 23bc015 fixes both. With a gzip-capable server (allow_gzip=True), the reads that failed before now match local reads: a deep partial read of 100.dat (frames 600000–600010), the last frames of a header without a length, and annotations through both read_annotations and rdann. Annotation.wrann and wfdb.wrann now raise "Writing to HTTP URLs is not supported", and local wrann writes still work. The signed-URL note is clear. The full offline suite, Ruff and the strict docs build pass locally.

Ready to merge once CI is green.

@tompollard
tompollard merged commit 2e0344e into main Dec 1, 2026
19 checks passed
@tompollard
tompollard deleted the explicit-http-record-paths branch December 1, 2026 04:04
tompollard added a commit that referenced this pull request Dec 1, 2026
## Summary

- Emit one `FutureWarning` when a public reader is called with `pn_dir`.
The warning suggests a `physionet://` path or a complete HTTP URL for a
custom server when the replacement can be formed without a network
request.
- Keep `pn_dir` calls working. Suppress warnings from internal reader
calls, including `download_records`.
- Update the remote-reading guide and add a changelog entry.

This is stacked on #817, which adds explicit HTTP URL reads for custom
servers. Merge #817 first, then retarget this PR to `main`. Related to
#534 and #672.

## Checks

- Offline suite: 1,543 passed, 4 skipped.
- Ruff check and format: passed.
- Sphinx HTML build with warnings as errors: passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant