azure.schemaregistry.serializer.avroserializer package

class azure.schemaregistry.serializer.avroserializer.AvroSerializer(**kwargs: Any)[source]

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

Keyword Arguments
  • 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.

close()None[source]

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

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

Decode bytes data.

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

Parameters

value (bytes) – The bytes data needs to be decoded.

Return type

Dict[str, Any]

Raises
serialize(value: Mapping[str, Any], **kwargs: Any)bytes[source]

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

Parameters

value (Mapping[str, Any]) – The data to be encoded.

Keyword Arguments

schema (str) – Required. The schema used to encode the data.

Return type

bytes

Raises

Submodules

azure.schemaregistry.serializer.avroserializer.exceptions module

exception azure.schemaregistry.serializer.avroserializer.exceptions.SchemaDeserializationError(message, *args, **kwargs)[source]

Error deserializing a JSON schema. :param str message: The message object stringified as ‘message’ attribute :keyword error: The original exception, if any

Variables
  • message (str) – A stringified version of the message parameter

  • inner_exception (Exception) – The exception passed with the ‘error’ kwarg

  • exc_type – The exc_type from sys.exc_info()

  • exc_value – The exc_value from sys.exc_info()

  • exc_traceback – The exc_traceback from sys.exc_info()

  • exc_msg – A string formatting of message parameter, exc_type and exc_value

raise_with_traceback()
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.schemaregistry.serializer.avroserializer.exceptions.SchemaParseError(message, *args, **kwargs)[source]

Error parsing a JSON schema. :param str message: The message object stringified as ‘message’ attribute :keyword error: The original exception, if any

Variables
  • message (str) – A stringified version of the message parameter

  • inner_exception (Exception) – The exception passed with the ‘error’ kwarg

  • exc_type – The exc_type from sys.exc_info()

  • exc_value – The exc_value from sys.exc_info()

  • exc_traceback – The exc_traceback from sys.exc_info()

  • exc_msg – A string formatting of message parameter, exc_type and exc_value

raise_with_traceback()
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception azure.schemaregistry.serializer.avroserializer.exceptions.SchemaSerializationError(message, *args, **kwargs)[source]

Error serializing a JSON schema. :param str message: The message object stringified as ‘message’ attribute :keyword error: The original exception, if any

Variables
  • message (str) – A stringified version of the message parameter

  • inner_exception (Exception) – The exception passed with the ‘error’ kwarg

  • exc_type – The exc_type from sys.exc_info()

  • exc_value – The exc_value from sys.exc_info()

  • exc_traceback – The exc_traceback from sys.exc_info()

  • exc_msg – A string formatting of message parameter, exc_type and exc_value

raise_with_traceback()
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args