Skip to main content

File-like object from url of remote file, optimized for use with h5py.

Project description


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/

import h5py
import remfile

url = ''

file = remfile.File(url)

with h5py.File(file, 'r') as f:

See examples/ 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.


pip install remfile


The conventional way of reading a remote hdf5 file is to use the fsspec library as in examples/ 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.


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.

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 = ''

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:


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


Apache 2.0


Jeremy Magland, Center for Computational Mathematics, Flatiron Institute

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remfile-0.1.13.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distribution

remfile-0.1.13-py3-none-any.whl (11.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page