Registry /
azure / azure-schemaregistry-avroserializer
Install & Compatibility
Where this runs
tested against v1.0.0b4.post1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.348s · 26.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.8s · import 0.332s · 27MB
24MB installed
● package 24MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AvroSerializer
✓ from azure.schemaregistry.serializer.avroserializer import AvroSerializer
✗ from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
The class was renamed from `SchemaRegistryAvroSerializer` to `AvroSerializer` in version 1.0.0b3.
SchemaRegistryClient
✓ from azure.schemaregistry import SchemaRegistryClient
Used to interact with the Schema Registry service itself.
DefaultAzureCredential
✓ from azure.identity import DefaultAzureCredential
Standard Azure SDK credential provider for authentication.
This quickstart demonstrates how to initialize the AvroSerializer, serialize Python dictionary data into Avro bytes, and then deserialize it back. It uses `DefaultAzureCredential` for authentication, requiring the `SCHEMA_REGISTRY_ENDPOINT` and `SCHEMA_REGISTRY_GROUP_NAME` environment variables to be set. The `auto_register_schemas` flag is set to `True` for convenience, but it is recommended to pre-register schemas in production environments.
import os
from azure.schemaregistry import SchemaRegistryClient
from azure.schemaregistry.serializer.avroserializer import AvroSerializer
from azure.identity import DefaultAzureCredential
# NOTE: This package is deprecated. Use azure-schemaregistry-avroencoder instead.
# Configure environment variables or replace placeholders
SCHEMA_REGISTRY_ENDPOINT = os.environ.get(
'SCHEMA_REGISTRY_ENDPOINT',
'https://<your-namespace>.servicebus.windows.net'
)
SCHEMA_REGISTRY_GROUP_NAME = os.environ.get(
'SCHEMA_REGISTRY_GROUP_NAME',
'my-schema-group'
)
# Define an Avro schema
AVRO_SCHEMA = '''
{
"type": "record",
"name": "TestMessage",
"namespace": "com.example",
"fields": [
{"name": "name", "type": "string"},
{"name": "value", "type": "int"}
]
}
'''
# Example data to serialize
message_data = {"name": "example", "value": 123}
def main():
print("Initializing Schema Registry and Avro Serializer...")
# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()
# Create a SchemaRegistryClient
schema_registry_client = SchemaRegistryClient(
fully_qualified_namespace=SCHEMA_REGISTRY_ENDPOINT,
credential=credential
)
# Create the AvroSerializer
# auto_register_schemas=True will automatically register the schema if not found
avro_serializer = AvroSerializer(
client=schema_registry_client,
group_name=SCHEMA_REGISTRY_GROUP_NAME,
auto_register_schemas=True # Consider disabling in production for performance
)
try:
# Serialize the data
print(f"Serializing data: {message_data}")
# The `schema` parameter is required for serialize in 1.0.0b4
encoded_data = avro_serializer.serialize(value=message_data, schema=AVRO_SCHEMA)
print(f"Serialized data (bytes): {encoded_data}")
# Deserialize the data
print(f"Deserializing data: {encoded_data}")
decoded_data = avro_serializer.deserialize(value=encoded_data)
print(f"Deserialized data: {decoded_data}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# It's good practice to close clients, especially in async scenarios
if hasattr(schema_registry_client, 'close'):
schema_registry_client.close()
if hasattr(avro_serializer, 'close'):
avro_serializer.close()
if __name__ == "__main__":
main()
Debug
Known issues
breakingThis package (`azure-schemaregistry-avroserializer`) is deprecated and no longer maintained. Users should migrate to `azure-schemaregistry-avroencoder` for new development and existing applications.fixInstall `azure-schemaregistry-avroencoder` and update code to use the `AvroEncoder` class and its methods. Consult the migration guide for detailed instructions.
affects: <=1.0.0b4.post1
breakingAPI class and parameter renames occurred between versions 1.0.0b3 and 1.0.0b4. `SchemaRegistryAvroSerializer` was renamed to `AvroSerializer`. The constructor parameters `schema_registry` and `schema_group` were renamed to `client` and `group_name`, respectively. The `serialize` and `deserialize` methods' `data` parameter was renamed to `value`.fixUpdate class instantiations to `AvroSerializer(client=..., group_name=...)` and method calls to `serialize(value=..., schema=...)` and `deserialize(value=...)`.
affects: >=1.0.0b3, <1.0.0b4
breakingPython 3.5 support was dropped in version 1.0.0b2. All future versions require Python 2.7 or 3.6+ (later updated to 3.7+ for `avroencoder`).fixEnsure your project uses Python 3.6+ (or 3.7+ if migrating to `avroencoder`).
affects: <1.0.0b2
gotchaFor Azure Active Directory (AAD) authentication, regional Schema Registry endpoints do not support AAD. You must create a custom subdomain for your Schema Registry resource to use AAD credentials.fixConfigure a custom subdomain for your Azure Schema Registry instance within your Event Hubs namespace.
affects: All versions
gotchaThe `auto_register_schemas` parameter (or `auto_register` in `avroencoder`) defaults to `False`. If set to `True`, schemas will be automatically registered on serialization if they don't exist. While convenient for development, it's recommended to pre-register schemas during deployment and set this to `False` in production to avoid first-event latency penalties and unintended schema creations.fixManage schema registration as part of your deployment pipeline. Set `auto_register_schemas=False` (or omit if it's the default) in production code.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.schemaregistry.serializer.avroserializer'
This error occurs because the `azure-schemaregistry-avroserializer` package, or its specific `serializer` submodule, is not installed or not found in the Python environment, or because it has been superseded.
fixInstall the recommended, currently maintained package `azure-schemaregistry-avroencoder` using `pip install azure-schemaregistry-avroencoder` and update your import statements to `from azure.schemaregistry.encoder.avroencoder import AvroEncoder`.
from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
This import pattern uses an older class name (`SchemaRegistryAvroSerializer`) and references a deprecated package. The class was renamed to `AvroSerializer` within the `azure-schemaregistry-avroserializer` package's later beta versions, and the entire package has since been superseded.
fixMigrate to the `azure-schemaregistry-avroencoder` package and import the `AvroEncoder` class: `from azure.schemaregistry.encoder.avroencoder import AvroEncoder`.
TypeError: AvroSerializer.__init__() missing 2 required positional arguments: 'client' and 'group_name'
This error indicates that you are trying to instantiate the `AvroSerializer` class (from the deprecated `azure-schemaregistry-avroserializer` package) without providing the required `client` and `group_name` keyword arguments, which became mandatory in later versions of the package.
fixUpdate your code to provide the `client` and `group_name` as keyword arguments, e.g., `serializer = AvroSerializer(client=schema_registry_client, group_name='your_schema_group')`. However, it is strongly recommended to migrate to `azure-schemaregistry-avroencoder` and use `AvroEncoder` with its corresponding constructor arguments.
SchemaParseError
This exception (or `SchemaSerializationError`, `SchemaDeserializationError`) is raised by the `azure-schemaregistry-avroserializer` package when there are issues parsing, serializing, or deserializing data due to an invalid or incompatible Avro schema.
fixEnsure your Avro schema is valid and compatible with the data being processed. If migrating, note that `azure-schemaregistry-avroencoder` replaces these with `InvalidContentError` and `InvalidSchemaError` for similar issues.
Upgrade
Version history
1.0.0b4.post1latest on PyPI · released Sep 7, 2023
Audit
Dependencies
azure-schemaregistryrequiredCore client for interacting with Azure Schema Registry. Required dependency for 1.0.0b4.
azure-identityrequiredRequired for Azure Active Directory (AAD) authentication.