AvroSerializer Class

AvroSerializer provides the ability to serialize and deserialize data according to the given avro schema. It would automatically register, get and cache the schema.

Inheritance
builtins.object
AvroSerializer

Constructor

AvroSerializer(**kwargs: Any)

Parameters

client
SchemaRegistryClient

Required. The schema registry client which is used to register schema and retrieve schema from the service.

group_name
str

Required. Schema group under which schema should be registered.

auto_register_schemas
bool

When true, register new schemas passed to serialize. Otherwise, and by default, serialization will fail if the schema has not been pre-registered in the registry.

Methods

close

This method is to close the sockets opened by the client. It need not be used when using with a context manager.

deserialize

Decode bytes data.

Data must follow format of associated Avro RecordSchema: https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema

serialize

Encode data with the given schema. The returns bytes are consisted of: The first 4 bytes denoting record format identifier. The following 32 bytes denoting schema id returned by schema registry service. The remaining bytes are the real data payload.

Schema must be an Avro RecordSchema: https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema

close

This method is to close the sockets opened by the client. It need not be used when using with a context manager.

close() -> None

deserialize

Decode bytes data.

Data must follow format of associated Avro RecordSchema: https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema

deserialize(value: bytes, **kwargs: Any) -> Dict[str, Any]

Parameters

value
bytes
Required

The bytes data needs to be decoded.

Return type

<xref:Dict>[str, <xref:Any>]

Exceptions

Indicates an issue with parsing schema.

Indicates an issue with deserializing value.

serialize

Encode data with the given schema. The returns bytes are consisted of: The first 4 bytes denoting record format identifier. The following 32 bytes denoting schema id returned by schema registry service. The remaining bytes are the real data payload.

Schema must be an Avro RecordSchema: https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema

serialize(value: Mapping[str, Any], **kwargs: Any) -> bytes

Parameters

value
<xref:Mapping>[str, <xref:Any>]
Required

The data to be encoded.

schema
str

Required. The schema used to encode the data.

Return type

Exceptions

Indicates an issue with parsing schema.

Indicates an issue with serializing data for provided schema.