Package: azure-schemaregistry
Azure Schema Registry client library for PythonAzure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning,
and management. The registry is leveraged by serializers to reduce payload size while describing payload structure with
schema identifiers rather than full schemas.Source code|Package (PyPi)|API reference documentation|Samples|ChangelogDisclaimerAzure SDK Python packages support for Python 2.7 has ended on 01 January 2022. For more information and questions, please refer tohttps://github.com/Azure/azure-sdk-for-python/issues/20691Getting startedInstall the packageInstall the Azure Schema Registry client library for Python withpip:pipinstallazure-schemaregistryPrerequisites:To use this package, you must have:Azure subscription -Create a free accountAzure Schema Registry-Here is the quickstart guideto create a Schema Registry group using the Azure portal.Python 3.7 or later -Install PythonAuthenticate the clientInteraction with Schema Registry starts with an instance of SchemaRegistryClient class. The client constructor takes the fully qualified namespace and an Azure Active Directory credential:The fully qualified namespace of the Schema Registry instance should follow the format:<yournamespace>.servicebus.windows.net.An AAD credential that implements theTokenCredentialprotocol should be passed to the constructor. There are implementations of theTokenCredentialprotocol available in theazure-identity package. To use the credential types provided byazure-identity, please install the Azure Identity client library for Python withpip:pipinstallazure-identityAdditionally, to use the async API,  you must first install an async transport, such asaiohttp:pipinstallaiohttpCreate client using the azure-identity library:fromazure.schemaregistryimportSchemaRegistryClientfromazure.identityimportDefaultAzureCredentialcredential=DefaultAzureCredential()# Namespace should be similar to: '<your-eventhub-namespace>.servicebus.windows.net/'fully_qualified_namespace='<< FULLY QUALIFIED NAMESPACE OF THE SCHEMA REGISTRY >>'schema_registry_client=SchemaRegistryClient(fully_qualified_namespace,credential)Key conceptsSchema: Schema is the organization or structure for data. More detailed information can be foundhere.Schema Group: A logical group of similar schemas based on business criteria, which can hold multiple versions of a schema. More detailed information can be foundhere.SchemaRegistryClient:SchemaRegistryClientprovides the API for storing and retrieving schemas in schema registry.ExamplesThe following sections provide several code snippets covering some of the most common Schema Registry tasks, including:Register a schemaGet the schema by idGet the schema by versionGet the id of a schemaRegister a schemaUseSchemaRegistryClient.register_schemamethod to register a schema.importosfromazure.identityimportDefaultAzureCredentialfromazure.schemaregistryimportSchemaRegistryClienttoken_credential=DefaultAzureCredential()fully_qualified_namespace=os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']group_name=os.environ['SCHEMA_REGISTRY_GROUP']name="your-schema-name"format="Avro"definition="""{"namespace": "example.avro","type": "record","name": "User","fields": [{"name": "name", "type": "string"},{"name": "favorite_number",  "type": ["int", "null"]},{"name": "favorite_color", "type": ["string", "null"]}]}"""schema_registry_client=SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace,credential=token_credential)withschema_registry_client:schema_properties=schema_registry_client.register_schema(group_name,name,definition,format)id=schema_properties.idGet the schema by idGet the schema definition and its properties by schema id.importosfromazure.identityimportDefaultAzureCredentialfromazure.schemaregistryimportSchemaRegistryClienttoken_credential=DefaultAzureCredential()fully_qualified_namespace=os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']schema_id='your-schema-id'schema_registry_client=SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace,credential=token_credential)withschema_registry_client:schema=schema_registry_client.get_schema(schema_id)definition=schema.definitionproperties=schema.propertiesGet the schema by versionGet the schema definition and its properties by schema version.importosfromazure.identityimportDefaultAzureCredentialfromazure.schemaregistryimportSchemaRegistryClienttoken_credential=DefaultAzureCredential()fully_qualified_namespace=os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']group_name=os.environ["SCHEMAREGISTRY_GROUP"]name="your-schema-name"version=int("<your schema version>")schema_registry_client=SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace,credential=token_credential)withschema_registry_client:schema=schema_registry_client.get_schema(group_name=group_name,name=name,version=version)definition=schema.definitionproperties=schema.propertiesGet the id of a schemaGet the schema id of a schema by schema definition and its properties.importosfromazure.identityimportDefaultAzureCredentialfromazure.schemaregistryimportSchemaRegistryClienttoken_credential=DefaultAzureCredential()fully_qualified_namespace=os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']group_name=os.environ['SCHEMA_REGISTRY_GROUP']name="your-schema-name"format="Avro"definition="""{"namespace": "example.avro","type": "record","name": "User","fields": [{"name": "name", "type": "string"},{"name": "favorite_number",  "type": ["int", "null"]},{"name": "favorite_color", "type": ["string", "null"]}]}"""schema_registry_client=SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace,credential=token_credential)withschema_registry_client:schema_properties=schema_registry_client.register_schema(group_name,name,definition,format)id=schema_properties.idTroubleshootingGeneralSchema Registry clients raise exceptions defined inAzure Core.LoggingThis library uses the standardlogginglibrary for logging.
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
level.Detailed DEBUG level logging, including request/response bodies and unredacted
headers, can be enabled on a client with thelogging_enableargument:importsysimportloggingfromazure.schemaregistryimportSchemaRegistryClientfromazure.identityimportDefaultAzureCredential# Create a logger for the SDKlogger=logging.getLogger('azure.schemaregistry')logger.setLevel(logging.DEBUG)# Configure a console outputhandler=logging.StreamHandler(stream=sys.stdout)logger.addHandler(handler)credential=DefaultAzureCredential()# This client will log detailed information about its HTTP sessions, at DEBUG levelschema_registry_client=SchemaRegistryClient("your_fully_qualified_namespace",credential,logging_enable=True)Similarly,logging_enablecan enable detailed logging for a single operation,
even when it isn't enabled for the client:schema_registry_client.get_schema(schema_id,logging_enable=True)Next stepsMore sample codePlease take a look at thesamplesdirectory for detailed examples of how to use this library to register and retrieve schema to/from Schema Registry.ContributingThis project welcomes contributions and suggestions.  Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visithttps://cla.microsoft.com.When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.This project has adopted theMicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor
contactopencode@microsoft.comwith any additional questions or comments.Release History1.2.0 (2022-10-10)This version and all future versions will require Python 3.7+, Python 3.6 is no longer supported.Features Addedgroup_name,name, andversionhave been added as optional parameters to theget_schemamethod on the sync and asyncSchemaRegistryClient.versionhas been added toSchemaProperties.Other ChangesUpdated azure-core minimum dependency to 1.24.0.Added distributed tracing support for sync and asyncSchemaRegistryClient.1.1.0 (2022-05-10)This version and all future versions will require Python 3.6+. Python 2.7 is no longer supported.Features Addedgroup_nameandnamehave been added as instance variables toSchemaProperties.Other ChangesUpdated azure-core minimum dependency to 1.23.0.1.0.0 (2021-11-10)Note:This is the first stable release of our efforts to create a user-friendly and Pythonic client library for Azure Schema Registry.Features AddedSchemaRegistryClientis the top-level client class interacting with the Azure Schema Registry Service. It provides three methods:register_schema: Store schema in the service by providing schema group name, schema name, schema definition, and schema format.get_schema: Get schema definition and its properties by schema id.get_schema_properties: Get schema properties by providing schema group name, schema name, schema definition, and schema format.SchemaPropertieshas the following instance variables:idandformat:The type offormathas been changed fromstrtoSchemaFormat.Schemahas the following properties:propertiesanddefinition.SchemaFormatprovides the schema format to be stored by the service. Currently, the only supported format isAvro.api_versionhas been added as a keyword arg to the sync and asyncSchemaRegistryClientconstructors.Breaking Changesversioninstance variable inSchemaPropertieshas been removed.schema_definitioninstance variable inSchemahas been renameddefinition.idparameter inget_schemamethod on sync and asyncSchemaRegistryClienthas been renamedschema_id.schema_definitionparameter inregister_schemaandget_schema_propertiesmethods on sync and asyncSchemaRegistryClienthas been renameddefinition.serializernamespace has been removed fromazure.schemaregistry.1.0.0b3 (2021-10-05)Breaking Changesget_schema_idmethod on sync and asyncSchemaRegistryClienthas been renamedget_schema_properties.schema_idparameter inget_schemamethod on sync and asyncSchemaRegistryClienthas been renamedid.register_schemaandget_schema_propertiesmethods on sync and asyncSchemaRegistryClientnow take in the following parameters in the given order:group_name, which has been renamed fromschema_groupname, which has been renamed fromschema_nameschema_definition, which has been renamed fromschema_contentformat, which has been renamed fromserialization_typeendpointparameter inSchemaRegistryClientconstructor has been renamedfully_qualified_namespacelocationinstance variable inSchemaPropertieshas been removed.SchemaandSchemaPropertiesno longer have positional parameters, as they will not be constructed by the user.Other ChangesUpdated azure-core dependency to 1.19.0.Removed caching support of registered schemas so requests are sent to the service to register schemas, get schema properties, and get schemas.1.0.0b2 (2021-08-17)This version and all future versions will require Python 2.7 or Python 3.6+, Python 3.5 is no longer supported.Features AddedSupport caching of registered schemas and send requests to the service only if the cache does not have the looked-up schema/schema ID.1.0.0b1 (2020-09-09)Version 1.0.0b1 is the first preview of our efforts to create a user-friendly and Pythonic client library for Azure Schema Registry.New featuresSchemaRegistryClientis the top-level client class interacting with the Azure Schema Registry Service. It provides three methods:register_schema: Store schema into the service.get_schema: Get schema content and its properties by schema id.get_schema_id: Get schema id and its properties by schema group, schema name, serialization type and schema content.