No project description provided
Project description
cached_path
A file utility library that provides a unified, simple interface for accessing both local and remote files. This can be used behind other APIs that need to access files agnostic to where they are located.
Installation
cached_path
requires Python 3.6.1 or later.
pip install cached_path
Usage
from cached_path import cached_path
Given something that might be a URL or local path, cached_path
determines which.
If it's a remote resource, it downloads the file and caches it, and
then returns the path to the cached file. If it's already a local path,
it makes sure the file exists and returns the path.
For URLs, "http://", "https://", "s3://", "gs://", and "hf://" are all supported. The latter corresponds to the HuggingFace Hub.
For example, to download the PyTorch weights for the model epwalsh/bert-xsmall-dummy
on HuggingFace, you could do:
cached_path("hf://epwalsh/bert-xsmall-dummy/pytorch_model.bin")
For paths or URLs that point to a tarfile or zipfile, you can also add a path
to a specific file to the url_or_filename
preceeded by a "!", and the archive will
be automatically extracted (provided you set extract_archive
to True
),
returning the local path to the specific file. For example:
cached_path("model.tar.gz!weights.th", extract_archive=True)
Team
cached_path
is developed and maintained by the AllenNLP team, backed by the Allen Institute for Artificial Intelligence (AI2).
AI2 is a non-profit institute with the mission to contribute to humanity through high-impact AI research and engineering.
To learn more about who specifically contributed to this codebase, see our contributors page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cached_path-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a3877524d664a5fba4d5cefa76dc26a1f7c2b6b511087c4a1efa108b6005fb8 |
|
MD5 | 6a78fe1ebdfeba07ca2f242bfbf29c9b |
|
BLAKE2b-256 | 5fff0a34bd6525b02b04f910968898e4bc410ba003b98fa92af0bdc4686ea080 |