Skip to content

google

Classes:

  • BlobStorage

    A storage backend that uses Google Cloud Storage.

  • ReaderType

    A protocol for creating a blob reader.

  • WriterType

    A protocol for creating a blob writer.

BlobPointer

Bases: TypedDict

A pointer to a blob in Google Cloud Storage.

Attributes:

  • blob (str) –

    The path to the blob within the bucket.

  • bucket (str) –

    The name of the bucket where the blob is stored.

  • user_project (NotRequired[str | None]) –

    The project ID to be billed for API requests made via the bucket.

blob instance-attribute

blob: str

The path to the blob within the bucket.

bucket instance-attribute

bucket: str

The name of the bucket where the blob is stored.

user_project instance-attribute

user_project: NotRequired[str | None]

The project ID to be billed for API requests made via the bucket.

BlobRouter

Bases: Protocol

A protocol for routing data to Google Cloud Storage by returning a BlobPointer.

BlobStorage

BlobStorage(
    *,
    storage_client: Client,
    storage_router: BlobRouter | None,
    object_chunk_size: int = DEFAULT_CHUNK_SIZE,
    max_writers: int | None = None,
    max_readers: int | None = None,
    writer_type: WriterType = BlobWriter,
    reader_type: ReaderType = BlobReader
)

Bases: Storage['BlobPointer']

A storage backend that uses Google Cloud Storage.

Methods:

deserialize_config

deserialize_config(config: str) -> C

Deserialize the configuration from a JSON string.

read_data async

read_data(pointer: BlobPointer) -> bytes

Load data from the given location.

read_data_stream async

read_data_stream(
    pointer: BlobPointer,
) -> AsyncGenerator[bytes]

Load a data stream from the given location.

serialize_config

serialize_config(config: C) -> str

Serialize the configuration to a JSON string.

write_data async

write_data(
    data: bytes, digest: Digest, tags: TagMap
) -> BlobPointer

Save the given data.

write_data_stream async

write_data_stream(
    data_stream: AsyncIterable[bytes],
    get_digest: GetStreamDigest,
    tags: TagMap,
) -> BlobPointer

Save the given data steam.

ReaderType

Bases: Protocol

A protocol for creating a blob reader.

WriterType

Bases: Protocol

A protocol for creating a blob writer.

simple_blob_router

simple_blob_router(
    bucket: str, prefix: str = ""
) -> BlobRouter

Create a simple blob router that returns a BlobPointer based on the bucket and prefix.

Parameters:

  • bucket

    (str) –

    The name of the Google Cloud Storage bucket.

  • prefix

    (str, default: '' ) –

    An optional prefix to prepend to the blob path.

Returns:

  • BlobRouter

    A BlobRouter that generates BlobPointers for the specified bucket and prefix.