Skip to content

storage

Classes:

  • Digest

    A digest describing serialized data.

  • GetStreamDigest

    A protocol for getting the digest of stream content.

  • Storage

    A protocol for storing and retrieving data.

  • StreamDigest

    A digest describing a stream of serialized data.

Digest

Bases: TypedDict

A digest describing serialized data.

Attributes:

content_encoding instance-attribute

content_encoding: str | None

The encoding of the data.

content_hash instance-attribute

content_hash: str

The hash of the data.

content_hash_algorithm instance-attribute

content_hash_algorithm: str

The algorithm used to hash the data.

content_size instance-attribute

content_size: int

The size of the data in bytes.

content_type instance-attribute

content_type: str

The MIME type of the data.

GetStreamDigest

Bases: Protocol

A protocol for getting the digest of stream content.

Storage

Bases: Generic[C], Component

A protocol for storing and retrieving data.

Methods:

  • deserialize_config

    Deserialize the configuration from a JSON string.

  • read_data

    Load data using the given information.

  • read_data_stream

    Load a stream of data using the given information.

  • serialize_config

    Serialize the configuration to a JSON string.

  • write_data

    Save the given data and return information that can be used to retrieve it.

  • write_data_stream

    Save the given stream and return information that can be used to retrieve it.

Attributes:

name class-attribute

The globally unique name of the component.

deserialize_config

deserialize_config(config: str) -> C

Deserialize the configuration from a JSON string.

read_data abstractmethod async

read_data(config: C) -> bytes

Load data using the given information.

read_data_stream abstractmethod

read_data_stream(info: C) -> AsyncGenerator[bytes]

Load a stream of data using the given information.

serialize_config

serialize_config(config: C) -> str

Serialize the configuration to a JSON string.

write_data abstractmethod async

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

Save the given data and return information that can be used to retrieve it.

Parameters:

  • data

    (bytes) –

    The data to save.

  • digest

    (Digest) –

    A digest describing the data.

  • tags

    (TagMap) –

    Tags from the user or unpacker that describe the data.

write_data_stream abstractmethod async

Save the given stream and return information that can be used to retrieve it.

Parameters:

  • data_stream

    (AsyncIterable[bytes]) –

    An async iterable that yields chunks of data to save.

  • get_digest

    (GetStreamDigest) –

    Function returning the digest of the stream content.

  • tags

    (TagMap) –

    Tags from the user or unpacker that describe the data.

StreamDigest

Bases: Digest

A digest describing a stream of serialized data.

Attributes:

content_encoding instance-attribute

content_encoding: str | None

The encoding of the data.

content_hash instance-attribute

content_hash: str

The hash of the data.

content_hash_algorithm instance-attribute

content_hash_algorithm: str

The algorithm used to hash the data.

content_size instance-attribute

content_size: int

The size of the data in bytes.

content_type instance-attribute

content_type: str

The MIME type of the data.

is_complete instance-attribute

is_complete: bool

A flag indicating whether the stream has been read in full.