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.

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

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.14.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remfile-0.1.14-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file remfile-0.1.14.tar.gz.

File metadata

  • Download URL: remfile-0.1.14.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for remfile-0.1.14.tar.gz
Algorithm Hash digest
SHA256 96b6b13ae086c93f59c8e37a411cd25fd8790d8a9627e006b795c0e3f0456c79
MD5 d357c4e9906ca3311a0311a336e4f9d7
BLAKE2b-256 8c29e4697cc348dba8074b07833733078c9d385a96f56a9ba7c8925d013b0ba2

See more details on using hashes here.

File details

Details for the file remfile-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: remfile-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for remfile-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 c13f618252bbed1dadd514513c426803dbcbcbf4d3fd87c58ca9e42ddd432af6
MD5 2957d71f9f2f7e162d7e81fff4a4efe1
BLAKE2b-256 0fe2649947ae3052bb8c3ea0cff6b3df3e22bf84b47e3ccace375c728895040c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.14 This release

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page