Skip to content

Serializers

See the ContentResponse section for usage.

asyncly.srvmocker.serialization.base.Serializer dataclass

Serializer(
    dumps: Callable[[Any], str | bytes], content_type: str
)

Pairs a serialization function with its HTTP content type.

Used by ContentResponse to render a body. Provide your own to support a custom wire format.

Attributes:

Name Type Description
dumps Callable[[Any], str | bytes]

Callable serializing a body to str or bytes.

content_type str

Value for the response Content-Type header.

asyncly.srvmocker.serialization.json.JsonSerializer module-attribute

JsonSerializer: Final = Serializer(
    dumps=dumps, content_type="application/json"
)

asyncly.srvmocker.serialization.msgpack.MsgpackSerializer module-attribute

MsgpackSerializer: Final = Serializer(
    dumps=encode, content_type="application/msgpack"
)

asyncly.srvmocker.serialization.toml.TomlSerializer module-attribute

TomlSerializer: Final = Serializer(
    dumps=dumps, content_type="application/toml"
)

asyncly.srvmocker.serialization.yaml.YamlSerializer module-attribute

YamlSerializer: Final = Serializer(
    dumps=dump, content_type="application/yaml"
)