Name | remfile JSON |
Version |
0.1.10
JSON |
| download |
home_page | https://github.com/magland/remfile |
Summary | File-like object from url of remote file, optimized for use with h5py. |
upload_time | 2024-01-13 13:59:34 |
maintainer | |
docs_url | None |
author | Jeremy Magland |
requires_python | |
license | |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# remfile
[](https://pypi.org/project/remfile)

[](https://codecov.io/gh/magland/remfile)
Provides a file-like object for reading a remote file over HTTP, optimized for use with h5py.
Example usage:
```python
# 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](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
```bash
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](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.
```python
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.
## License
Apache 2.0
## Author
Jeremy Magland, Center for Computational Mathematics, Flatiron Institute
Raw data
{
"_id": null,
"home_page": "https://github.com/magland/remfile",
"name": "remfile",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Jeremy Magland",
"author_email": "jmagland@flatironinstitute.org",
"download_url": "https://files.pythonhosted.org/packages/61/34/64cc64aa71159bedcda13846dd0cb6b79c12ba04fb6bc61a32c57df2b958/remfile-0.1.10.tar.gz",
"platform": null,
"description": "# remfile\n\n[](https://pypi.org/project/remfile)\n\n[](https://codecov.io/gh/magland/remfile)\n\nProvides a file-like object for reading a remote file over HTTP, optimized for use with h5py.\n\nExample usage:\n\n```python\n# See examples/example1.py\n\nimport h5py\nimport remfile\n\nurl = 'https://dandiarchive.s3.amazonaws.com/blobs/d86/055/d8605573-4639-4b99-a6d9-e0ac13f9a7df'\n\nfile = remfile.File(url)\n\nwith h5py.File(file, 'r') as f:\n print(f['/'].keys())\n```\n\nSee [examples/example1.py](examples/example1.py) for a more complete example.\n\nNote: 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.\n\n## Installation\n\n```bash\npip install remfile\n```\n\n## Why?\n\nThe conventional way of reading a remote hdf5 file is to use the fsspec library as in [examples/example1_compare_fsspec.py](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.\n\nSee a timing comparison betweeen remfile and fsspec in the examples directory.\n\nFurthermore, 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.\n\n## How?\n\nA 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.\n\n## Disk caching\n\nThe 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.\n\n```python\nimport remfile\n\nurl = 'https://dandiarchive.s3.amazonaws.com/blobs/d86/055/d8605573-4639-4b99-a6d9-e0ac13f9a7df'\n\ncache_dirname = '/tmp/remfile_test_cache'\ndisk_cache = remfile.DiskCache(cache_dirname)\n\nfile = remfile.File(url, disk_cache=disk_cache)\n\nwith h5py.File(file, 'r') as f:\n print(f['/'].keys())\n```\n\n## Caveats\n\nThis library is not intended to be a general purpose library for reading remote files. It is optimized for reading hdf5 files.\n\n## License\n\nApache 2.0\n\n## Author\n\nJeremy Magland, Center for Computational Mathematics, Flatiron Institute\n",
"bugtrack_url": null,
"license": "",
"summary": "File-like object from url of remote file, optimized for use with h5py.",
"version": "0.1.10",
"project_urls": {
"Homepage": "https://github.com/magland/remfile"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "090dcece103204a19acb930e133ce96f2fec1ea5de998f263f308887ae3050c4",
"md5": "e4c03747ac6a04ed29d687e23dd76703",
"sha256": "0184b8e17935c3dc7ae24d6eb452b0ba718f171d97b20a9d43776aff64f9587a"
},
"downloads": -1,
"filename": "remfile-0.1.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e4c03747ac6a04ed29d687e23dd76703",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11168,
"upload_time": "2024-01-13T13:59:32",
"upload_time_iso_8601": "2024-01-13T13:59:32.391939Z",
"url": "https://files.pythonhosted.org/packages/09/0d/cece103204a19acb930e133ce96f2fec1ea5de998f263f308887ae3050c4/remfile-0.1.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "613464cc64aa71159bedcda13846dd0cb6b79c12ba04fb6bc61a32c57df2b958",
"md5": "7070c01c584a34b4e73b573977d7b433",
"sha256": "f1cfc5bcbbc45c94a48ce9fd260d0eff1c9364a2a93e01b8fa4bdfbec7ae8473"
},
"downloads": -1,
"filename": "remfile-0.1.10.tar.gz",
"has_sig": false,
"md5_digest": "7070c01c584a34b4e73b573977d7b433",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11583,
"upload_time": "2024-01-13T13:59:34",
"upload_time_iso_8601": "2024-01-13T13:59:34.292777Z",
"url": "https://files.pythonhosted.org/packages/61/34/64cc64aa71159bedcda13846dd0cb6b79c12ba04fb6bc61a32c57df2b958/remfile-0.1.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-13 13:59:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "magland",
"github_project": "remfile",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "remfile"
}