Skip to main content

GCSBackendBase

Google Cloud Storage task result backend.

Attributes

AttributeTypeDescription
_client_lockRLockReentrant lock used to ensure thread-safe access and initialization of the Google Cloud Storage client.
_pidintThe process ID of the current process, used to detect forks and ensure each process maintains its own client connection.
_retry_policygoogle.api_core.retry.Retry = DEFAULT_RETRYThe retry policy applied to Google Cloud Storage operations like downloading, uploading, or deleting blobs.
_clientgoogle.cloud.storage.client.Client = nullInternal cache for the Google Cloud Storage client instance.
bucket_namestringThe name of the Google Cloud Storage bucket where task results are stored.
projectstringThe Google Cloud project ID associated with the storage bucket.
base_pathstring = ""A prefix path within the bucket used to namespace stored task results.
_threadpool_maxsizeint = 10The maximum number of concurrent connections allowed in the HTTP adapter pool for the storage client.
ttlfloat = 0The time-to-live in seconds for stored results, requiring a corresponding bucket lifecycle rule if non-zero.
clientgoogle.cloud.storage.client.ClientReturns a storage client.
bucketgoogle.cloud.storage.bucket.BucketThe Google Cloud Storage bucket object derived from the configured bucket name and client.

Constructor

Signature

def GCSBackendBase(
**kwargs: dict
)

Parameters

NameTypeDescription
**kwargsdictArbitrary keyword arguments passed to the parent KeyValueStoreBackend class.

Methods


get()

@classmethod
def get(
key: string
) - > bytes

Retrieves the binary content of a specific object from the GCS bucket. Returns None if the object does not exist.

Parameters

NameTypeDescription
keystringThe unique identifier for the object to retrieve from the storage bucket.

Returns

TypeDescription
bytesThe raw bytes downloaded from the GCS blob, or None if the key is not found.

set()

@classmethod
def set(
key: string,
value: string
) - > null

Uploads data to a GCS blob and optionally sets a custom expiration time if a TTL is configured.

Parameters

NameTypeDescription
keystringThe destination path or name for the object in the GCS bucket.
valuestringThe data content to be uploaded to the storage backend.

Returns

TypeDescription
nullNo return value.

delete()

@classmethod
def delete(
key: string
) - > null

Removes an object from the GCS bucket if it exists.

Parameters

NameTypeDescription
keystringThe identifier of the object to be deleted from storage.

Returns

TypeDescription
nullNo return value.

mget()

@classmethod
def mget(
keys: list
) - > list

Fetches multiple objects concurrently using a thread pool to improve performance for batch operations.

Parameters

NameTypeDescription
keyslistA collection of object identifiers to retrieve from the bucket.

Returns

TypeDescription
listA list of byte strings corresponding to the requested keys, in the same order as provided.

client()

@classmethod
def client() - > google.cloud.storage.client.Client

Returns a storage client.

Returns

TypeDescription
google.cloud.storage.client.ClientA thread-safe GCS client instance configured with connection pooling and process-specific sessions.

bucket()

@classmethod
def bucket() - > google.cloud.storage.bucket.Bucket

Accesses the specific GCS bucket instance configured for this backend.

Returns

TypeDescription
google.cloud.storage.bucket.BucketThe bucket object used for all storage operations.