faust.serializers.registry

Registry of supported codecs (serializers, compressors, etc.).

class faust.serializers.registry.Registry(key_serializer: Optional[Union[CodecT, str]] = None, value_serializer: Optional[Union[CodecT, str]] = 'json')[source]

Serializing message keys/values.

Parameters:
  • key_serializer (_UnionGenericAlias[CodecT, str, None]) – Default key serializer to use when none provided.

  • value_serializer (_UnionGenericAlias[CodecT, str, None]) – Default value serializer to use when none provided.

loads_key(typ: Optional[Union[Type[ModelT], Type[bytes], Type[str]]], key: Optional[bytes], *, serializer: Optional[Union[CodecT, str]] = None) Optional[Union[bytes, _ModelT, Any]][source]

Deserialize message key.

Parameters:
  • typ (_UnionGenericAlias[_GenericAlias[ModelT], _GenericAlias[bytes], _GenericAlias[str], None]) – Model to use for deserialization.

  • key (_UnionGenericAlias[bytes, None]) – Serialized key.

  • serializer (_UnionGenericAlias[CodecT, str, None]) – Codec to use for this value. If not set the default will be used (key_serializer).

Return type:

_UnionGenericAlias[bytes, _ModelT, Any, None]

loads_value(typ: Optional[Union[Type[ModelT], Type[bytes], Type[str]]], value: Optional[bytes], *, serializer: Optional[Union[CodecT, str]] = None) Any[source]

Deserialize value.

Parameters:
  • typ (_UnionGenericAlias[_GenericAlias[ModelT], _GenericAlias[bytes], _GenericAlias[str], None]) – Model to use for deserialization.

  • value (_UnionGenericAlias[bytes, None]) – bytes to deserialize.

  • serializer (_UnionGenericAlias[CodecT, str, None]) – Codec to use for this value. If not set the default will be used (value_serializer).

Return type:

Any

dumps_key(typ: ~typing.Optional[~typing.Union[~typing.Type[~faust.types.models.ModelT], ~typing.Type[bytes], ~typing.Type[str]]], key: ~typing.Optional[~typing.Union[bytes, ~faust.types.core._ModelT, ~typing.Any]], *, serializer: ~typing.Optional[~typing.Union[~faust.types.codecs.CodecT, str]] = None, skip: ~typing.Tuple[~typing.Type, ...] = (<class 'bytes'>,)) Optional[bytes][source]

Serialize key.

Parameters:
  • typ (_UnionGenericAlias[_GenericAlias[ModelT], _GenericAlias[bytes], _GenericAlias[str], None]) – Model hint (can also be str/bytes). When typ=str or bytes, raw serializer is assumed.

  • key (_UnionGenericAlias[bytes, _ModelT, Any, None]) – The key value to serializer.

  • serializer (_UnionGenericAlias[CodecT, str, None]) – Codec to use for this key, if it is not a model type. If not set the default will be used (key_serializer).

Return type:

_UnionGenericAlias[bytes, None]

dumps_value(typ: ~typing.Optional[~typing.Union[~typing.Type[~faust.types.models.ModelT], ~typing.Type[bytes], ~typing.Type[str]]], value: ~typing.Union[bytes, ~faust.types.core._ModelT, ~typing.Any], *, serializer: ~typing.Optional[~typing.Union[~faust.types.codecs.CodecT, str]] = None, skip: ~typing.Tuple[~typing.Type, ...] = (<class 'bytes'>,)) Optional[bytes][source]

Serialize value.

Parameters:
  • typ (_UnionGenericAlias[_GenericAlias[ModelT], _GenericAlias[bytes], _GenericAlias[str], None]) – Model hint (can also be str/bytes). When typ=str or bytes, raw serializer is assumed.

  • key – The value to serializer.

  • serializer (_UnionGenericAlias[CodecT, str, None]) – Codec to use for this value, if it is not a model type. If not set the default will be used (value_serializer).

Return type:

_UnionGenericAlias[bytes, None]

Model[source]

Return the faust.Model class used by this serializer.