Skip to main content

remfile

latest-release tests codecov

Provides a file-like object for reading a remote file over HTTP, optimized for use with h5py.

Example usage:

# See examples/example1.py

import h5py
import remfile

url = 'https://dandiarchive.s3.amazonaws.com/blobs/d86/055/d8605573-4639-4b99-a6d9-e0ac13f9a7df'

file = remfile.File(url)

with h5py.File(file, 'r') as f:
    print(f['/'].keys())

See examples/example1.py for a more complete example.

Note: url can either be a string or an object that has a get_url() method. The latter is useful if the url is a presigned AWS URL that expires after a certain amount of time. However, if you implement your own get_url() method, make sure it renews the signed URL only when necessary.

Installation

pip install remfile

Why?

The conventional way of reading a remote hdf5 file is to use the fsspec library as in examples/example1_compare_fsspec.py. However, this approach is empirically much slower than using remfile. I am not familiar with the inner workings of fsspec, but it appears that it is not optimized for reading hdf5 files. Efficient access of remote hdf5 files requires reading small chunks of data to obtain meta information, and then large chunks of data, and parallelization, to obtain the larger data arrays.

See a timing comparison betweeen remfile and fsspec in the examples directory.

Furthermore, since the url can be an object with a get_url() method, it is possible to use remfile in a context where presigned URLs need to be renewed. As mentioned above, if you implement your own get_url() method, make sure it renews the signed URL only when necessary.

How?

A file-like object is created that reads the remote file in chunks using the requests library. A relatively small default chunk size is used, but when remfile detects that a large data array is being accessed, it adaptively switches to larger chunk sizes. For very large data arrays, the system will use multiple threads to read the data in parallel.

Timeouts and closing

Each HTTP request times out after 30 seconds without connecting or 60 seconds without receiving data, so that a stalled connection cannot hang forever. A request that times out is retried like any other failed request. Pass timeout to change this (a number, or a (connect, read) tuple, as accepted by requests), or timeout=None for no timeout.

A file can be used as a context manager, which closes its connections on exit:

with remfile.File(url) as file, h5py.File(file, 'r') as f:
    print(f['/'].keys())

Disk caching

The following example shows how to use disk caching. It is important to note that this is not an LRU cache, so there is no cleanup operation. The cache will grow until the disk is full. Therefore, you are responsible for deleting the directory when you are done with it.

import remfile

url = 'https://dandiarchive.s3.amazonaws.com/blobs/d86/055/d8605573-4639-4b99-a6d9-e0ac13f9a7df'

cache_dirname = '/tmp/remfile_test_cache'
disk_cache = remfile.DiskCache(cache_dirname)

file = remfile.File(url, disk_cache=disk_cache)

with h5py.File(file, 'r') as f:
    print(f['/'].keys())

Caveats

This library is not intended to be a general purpose library for reading remote files. It is optimized for reading hdf5 files.

Comparison with fsspec method

See pynwb_streaming_benchmark

License

Apache 2.0

Author

Jeremy Magland, Center for Computational Mathematics, Flatiron Institute

Metadata

Release files for remfile 0.1.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for remfile 0.1.17
File Size Uploaded Provenance Actions
remfile-0.1.17.tar.gz 24.8 kB With provenance Details for remfile-0.1.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for remfile 0.1.17
File Interpreter ABI Platform Actions
remfile-0.1.17-py3-none-any.whl Python 3 none any Details for remfile-0.1.17-py3-none-any.whl

Total release size: 41.0 kB

Release files / remfile-0.1.17.tar.gz

Download URL remfile-0.1.17.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ff1479f30d6c93d451f9ebdaf14c5a1eb3fa9a95c7da7045489f44d3958e3e2e
BLAKE2b-256 checksum
How to use checksums
91b2b16439d42c7d979c2afda5467445935678d7cb6d1ea855c08fc148c70caa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / remfile-0.1.17-py3-none-any.whl

Download URL remfile-0.1.17-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78eee6f4a31001251f81aaa6e8c6791bbc273033439a0e16f51d3d12203a5c1b
BLAKE2b-256 checksum
How to use checksums
8dac926ab1e8b382080f0d606c71b0f68b677ff9b3f546a5b39dbf2b6f3d17d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for remfile 0.1.17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for remfile-0.1.17.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page