storage#
- class cloudly.gcp.storage.GcsBlobUpath[source]#
Bases:
BlobUpathGcsBlobUpath implements the
UpathAPI for Google Cloud Storage using the package google-cloud-storage.- __init__(*paths: str, bucket_name: str | None = None)[source]#
If
bucket_nameisNone, then*pathsshould be a single string starting with ‘gs://<bucket-name>/’.If
bucket_nameis specified, then*pathsspecify path components under the root of the bucket.Examples
These several calls are equivalent:
>>> GcsBlobUpath('experiments', 'data', 'first.data', bucket_name='backup') GcsBlobUpath('gs://backup/experiments/data/first.data') >>> GcsBlobUpath('/experiments/data/first.data', bucket_name='backup') GcsBlobUpath('gs://backup/experiments/data/first.data') >>> GcsBlobUpath('gs://backup/experiments/data/first.data') GcsBlobUpath('gs://backup/experiments/data/first.data') >>> GcsBlobUpath('gs://backup', 'experiments', 'data/first.data') GcsBlobUpath('gs://backup/experiments/data/first.data')
- is_file() bool[source]#
The result of this call is not cached, in case the object is modified anytime by other clients.
- is_dir() bool[source]#
If there is a dummy blob with name
f"{self.name}/", this will returnTrue. This is the case after creating a “folder” on the GCP dashboard. In programmatic use, it’s recommended to avoid such situations so thatis_dir()returnsTrueif and only if there are blobs “under” the current path.
- file_info(*, timeout=None) FileInfo | None[source]#
Return file info if the current path is a file; otherwise return
None.
- property root: GcsBlobUpath#
Return a new path representing the root of the same bucket.
- write_bytes(data: bytes | BufferedReader, *, overwrite=False, **kwargs)[source]#
Write bytes
datato the current blob.In the usual case,
datais bytes. The case wheredatais a io.BufferedReader object, such as an open file, is not well tested.
- remove_dir(**kwargs) int[source]#
Remove the current dir and all the content under it recursively. Return the number of blobs removed.
- lock(*, timeout=None)[source]#
This implementation does not prevent the file from being deleted by other workers that does not use this method. It relies on the assumption that this blob is used cooperatively solely between workers in this locking logic.
timeoutis the wait time for acquiring or releasing the lease. IfNone, the default value 600 seconds is used. If0, exactly one attempt is made to acquire a lock.Note: timeout = None does not mean infinite wait. It means a default wait time. If user wants longer wait, just pass in a large number.