storage#

class cloudly.gcp.storage.GcsBlobUpath[source]#

Bases: BlobUpath

GcsBlobUpath implements the Upath API for Google Cloud Storage using the package google-cloud-storage.

__init__(*paths: str, bucket_name: str | None = None)[source]#

If bucket_name is None, then *paths should be a single string starting with ‘gs://<bucket-name>/’.

If bucket_name is specified, then *paths specify 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')
as_uri() str[source]#

Represent the path as a file URI, like ‘gs://bucket-name/path/to/blob’.

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 return True. This is the case after creating a “folder” on the GCP dashboard. In programmatic use, it’s recommended to avoid such situations so that is_dir() returns True if 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 data to the current blob.

In the usual case, data is bytes. The case where data is a io.BufferedReader object, such as an open file, is not well tested.

read_bytes(**kwargs) bytes[source]#

Return the content of the current blob as bytes.

iterdir() Iterator[Self][source]#

Yield immediate children under the current dir.

remove_dir(**kwargs) int[source]#

Remove the current dir and all the content under it recursively. Return the number of blobs removed.

remove_file(missing_ok: bool = False) None[source]#

Remove the current blob.

riterdir() Iterator[Self][source]#

Yield all blobs recursively under the current dir.

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.

timeout is the wait time for acquiring or releasing the lease. If None, the default value 600 seconds is used. If 0, 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.

open(mode='r', **kwargs)[source]#

Use this on a blob (not a “directory”) as a context manager. See Google documentation.

read_meta() dict[str, str][source]#
write_meta(data: dict[str, str])[source]#