Skip to content

serializer

Classes:

SerializedData

Bases: Generic[C], TypedDict

The serialized representation of a value.

Attributes:

config instance-attribute

config: NotRequired[C]

Additional configuration for the serializer, if any.

content_encoding instance-attribute

content_encoding: str | None

The encoding of the data.

content_type instance-attribute

content_type: str

The MIME type of the data.

data instance-attribute

data: bytes

The serialized data.

SerializedDataStream

Bases: Generic[C], TypedDict

The serialized representation of a stream of values.

Attributes:

config instance-attribute

config: NotRequired[C]

Additional configuration for the serializer, if any.

content_encoding instance-attribute

content_encoding: str | None

The encoding of the data.

content_type instance-attribute

content_type: str

The MIME type of the data.

data_stream instance-attribute

data_stream: AsyncGenerator[bytes]

The serialized data stream.

Serializer

Bases: _BaseSerializer[T, C], Component

A protocol for serializing/deserializing values.

Methods:

Attributes:

content_types class-attribute instance-attribute

content_types: tuple[str, ...] = ()

The content types that the serializer uses.

Used to get serializers by content type in the registry.

name class-attribute

The globally unique name of the component.

types class-attribute instance-attribute

types: tuple[type[T], ...] = ()

The types that the serializer can handle

Used for type inference in the registry.

deserialize_config

deserialize_config(config: str) -> C

Deserialize the configuration from a JSON string.

deserialize_data abstractmethod

deserialize_data(content: SerializedData[C]) -> T

Deserialize the given value.

serialize_config

serialize_config(config: C) -> str

Serialize the configuration to a JSON string.

serialize_data abstractmethod

serialize_data(value: T) -> SerializedData[C]

Serialize the given value.

StreamSerializer

Bases: _BaseSerializer[T, C], Component

A protocol for serializing/deserializing streams of values.

Methods:

Attributes:

content_types class-attribute instance-attribute

content_types: tuple[str, ...] = ()

The content types that the serializer uses.

Used to get serializers by content type in the registry.

name class-attribute

The globally unique name of the component.

types class-attribute instance-attribute

types: tuple[type[T], ...] = ()

The types that the serializer can handle

Used for type inference in the registry.

deserialize_config

deserialize_config(config: str) -> C

Deserialize the configuration from a JSON string.

deserialize_data_stream abstractmethod

deserialize_data_stream(
    content: SerializedDataStream[C],
) -> AsyncGenerator[T]

Deserialize the given stream.

serialize_config

serialize_config(config: C) -> str

Serialize the configuration to a JSON string.

serialize_data_stream abstractmethod

serialize_data_stream(
    stream: AsyncIterable[T],
) -> SerializedDataStream[C]

Serialize the given stream.