Read GCS and local paths with the same interface, clone of tensorflow.io.gfile
Project description
blobfile
This is a standalone clone of TensorFlow's gfile
, supporting both local paths and gs://
(Google Cloud Storage) paths.
The main function is BlobFile
, a replacement for GFile
. There are also a few additional functions, basename
, dirname
, and join
, which mostly do the same thing as their os.path
namesakes, only they also support gs://
paths.
Installation:
pip install blobfile
Usage:
import blobfile as bf
with bf.BlobFile("gs://my-bucket-name/cats", "wb") as w:
w.write(b"meow!")
Here are the functions:
BlobFile
- likeopen()
but works withgs://
paths tooLocalBlobFile
- likeBlobFile()
but operations take place on a local file. When reading, this is done by downloading the file during the constructor. When writing, this means uploading the file onclose()
or during destruction. You can pass acache_dir
parameter to cache files for reading. You are reponsible for cleaning up the cache directory.
Some are inspired by existing os.path
and shutil
functions:
copy
- copy a file from one path to another, will do a remote copy between two remote paths on the same blob storage serviceexists
- returnsTrue
if the file or directory existsglob
- return files matching a pattern, on GCS this only supports a single*
operator. In addition, it can be slow if the*
appears early in the pattern since GCS can only do prefix matches; all additional filtering must happen locallyisdir
- returnsTrue
if the path is a directorylistdir
- list contents of a directory as a generatormakedirs
- ensure that a directory and all parent directories existremove
- remove a filermdir
- remove an empty directoryrmtree
- remove a directory treestat
- get the size and modification time of a filewalk
- walk a directory tree with a generator that yields(dirpath, dirnames, filenames)
tuplesbasename
- get the final component of a pathdirname
- get the path except for the final componentjoin
- join 2 or more paths together, inserting directory separators between each component
There are a few bonus functions:
get_url
- returns a url for a path along with the expiration for that url (or None)md5
- get the md5 hash for a path, for GCS this is fast, but for other backends this may be slowset_log_callback
- set a log callback functionlog(msg: string)
to use instead of printing to stdout
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
blobfile-0.10.0-py3-none-any.whl
(30.3 kB
view details)
File details
Details for the file blobfile-0.10.0-py3-none-any.whl
.
File metadata
- Download URL: blobfile-0.10.0-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82057cb3205e5f4763cba37d81058aadabc568affc44322833d7646c4ea49d7e |
|
MD5 | e8ea61e795c6d988c4d53214b046852a |
|
BLAKE2b-256 | f23ec2a1649e23fa951add38fc91deae5629718de264a4046d7e28f1925e9ea3 |