{"id":5583,"library":"azure-schemaregistry-avroserializer","title":"Azure Schema Registry Avro Serializer","description":"The `azure-schemaregistry-avroserializer` is a Python client library for serializing and deserializing data in Apache Avro format using Azure Schema Registry. As of version 1.0.0b4.post1, this package is no longer maintained and has been superseded by `azure-schemaregistry-avroencoder`. It provided functionalities for schema storage, versioning, and management in Azure Event Hubs. New projects should use the `avroencoder` package instead.","status":"deprecated","version":"1.0.0b4.post1","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","schema registry","avro","serialization","deprecated","eventhubs"],"install":[{"cmd":"pip install azure-schemaregistry-avroserializer","lang":"bash","label":"Install Deprecated Package"},{"cmd":"pip install azure-schemaregistry-avroencoder azure-identity azure-eventhub","lang":"bash","label":"Install Recommended Replacement"}],"dependencies":[{"reason":"Core client for interacting with Azure Schema Registry. Required dependency for 1.0.0b4.","package":"azure-schemaregistry","optional":false},{"reason":"Required for Azure Active Directory (AAD) authentication.","package":"azure-identity","optional":false}],"imports":[{"note":"The class was renamed from `SchemaRegistryAvroSerializer` to `AvroSerializer` in version 1.0.0b3.","wrong":"from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer","symbol":"AvroSerializer","correct":"from azure.schemaregistry.serializer.avroserializer import AvroSerializer"},{"note":"Used to interact with the Schema Registry service itself.","symbol":"SchemaRegistryClient","correct":"from azure.schemaregistry import SchemaRegistryClient"},{"note":"Standard Azure SDK credential provider for authentication.","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.schemaregistry import SchemaRegistryClient\nfrom azure.schemaregistry.serializer.avroserializer import AvroSerializer\nfrom azure.identity import DefaultAzureCredential\n\n# NOTE: This package is deprecated. Use azure-schemaregistry-avroencoder instead.\n\n# Configure environment variables or replace placeholders\nSCHEMA_REGISTRY_ENDPOINT = os.environ.get(\n    'SCHEMA_REGISTRY_ENDPOINT',\n    'https://<your-namespace>.servicebus.windows.net'\n)\nSCHEMA_REGISTRY_GROUP_NAME = os.environ.get(\n    'SCHEMA_REGISTRY_GROUP_NAME',\n    'my-schema-group'\n)\n\n# Define an Avro schema\nAVRO_SCHEMA = '''\n{\n    \"type\": \"record\",\n    \"name\": \"TestMessage\",\n    \"namespace\": \"com.example\",\n    \"fields\": [\n        {\"name\": \"name\", \"type\": \"string\"},\n        {\"name\": \"value\", \"type\": \"int\"}\n    ]\n}\n'''\n\n# Example data to serialize\nmessage_data = {\"name\": \"example\", \"value\": 123}\n\ndef main():\n    print(\"Initializing Schema Registry and Avro Serializer...\")\n    # Authenticate using DefaultAzureCredential\n    credential = DefaultAzureCredential()\n\n    # Create a SchemaRegistryClient\n    schema_registry_client = SchemaRegistryClient(\n        fully_qualified_namespace=SCHEMA_REGISTRY_ENDPOINT,\n        credential=credential\n    )\n\n    # Create the AvroSerializer\n    # auto_register_schemas=True will automatically register the schema if not found\n    avro_serializer = AvroSerializer(\n        client=schema_registry_client,\n        group_name=SCHEMA_REGISTRY_GROUP_NAME,\n        auto_register_schemas=True # Consider disabling in production for performance\n    )\n\n    try:\n        # Serialize the data\n        print(f\"Serializing data: {message_data}\")\n        # The `schema` parameter is required for serialize in 1.0.0b4\n        encoded_data = avro_serializer.serialize(value=message_data, schema=AVRO_SCHEMA)\n        print(f\"Serialized data (bytes): {encoded_data}\")\n\n        # Deserialize the data\n        print(f\"Deserializing data: {encoded_data}\")\n        decoded_data = avro_serializer.deserialize(value=encoded_data)\n        print(f\"Deserialized data: {decoded_data}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n    finally:\n        # It's good practice to close clients, especially in async scenarios\n        if hasattr(schema_registry_client, 'close'):\n            schema_registry_client.close()\n        if hasattr(avro_serializer, 'close'):\n            avro_serializer.close()\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"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."},"warnings":[{"fix":"Install `azure-schemaregistry-avroencoder` and update code to use the `AvroEncoder` class and its methods. Consult the migration guide for detailed instructions.","message":"This package (`azure-schemaregistry-avroserializer`) is deprecated and no longer maintained. Users should migrate to `azure-schemaregistry-avroencoder` for new development and existing applications.","severity":"breaking","affected_versions":"<=1.0.0b4.post1"},{"fix":"Update class instantiations to `AvroSerializer(client=..., group_name=...)` and method calls to `serialize(value=..., schema=...)` and `deserialize(value=...)`.","message":"API 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`.","severity":"breaking","affected_versions":">=1.0.0b3, <1.0.0b4"},{"fix":"Ensure your project uses Python 3.6+ (or 3.7+ if migrating to `avroencoder`).","message":"Python 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`).","severity":"breaking","affected_versions":"<1.0.0b2"},{"fix":"Configure a custom subdomain for your Azure Schema Registry instance within your Event Hubs namespace.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Manage schema registration as part of your deployment pipeline. Set `auto_register_schemas=False` (or omit if it's the default) in production code.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}