azure.schemaregistry.aio package

class azure.schemaregistry.aio.SchemaRegistryClient(endpoint: str, credential: AsyncTokenCredential, **kwargs: Any)[source]

SchemaRegistryClient is as a central schema repository for enterprise-level data infrastructure, complete with support for versioning and management.

Parameters
  • endpoint (str) – The Schema Registry service endpoint, for example my-namespace.servicebus.windows.net.

  • credential (AsyncTokenCredential) – To authenticate to manage the entities of the SchemaRegistry namespace.

Example:

Create a new instance of the SchemaRegistryClient.
SCHEMA_REGISTRY_ENDPOINT = os.environ['SCHEMA_REGISTRY_ENDPOINT']
token_credential = DefaultAzureCredential()
schema_registry_client = SchemaRegistryClient(endpoint=SCHEMA_REGISTRY_ENDPOINT, credential=token_credential)
async 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.

async get_schema(schema_id: str, **kwargs: Any) → azure.schemaregistry._common._schema.Schema[source]

Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace.

Parameters

schema_id (str) – References specific schema in registry namespace.

Return type

Schema

Example:

Get schema by id.
schema = await schema_registry_client.get_schema(schema_id)
schema_content = schema.schema_content
async get_schema_id(schema_group: str, schema_name: str, serialization_type: str, schema_content: str, **kwargs: Any) → azure.schemaregistry._common._schema.SchemaProperties[source]

Gets the ID referencing an existing schema within the specified schema group, as matched by schema content comparison.

Parameters
  • schema_group (str) – Schema group under which schema should be registered.

  • schema_name (str) – Name of schema being registered.

  • serialization_type (Union[str, SerializationType]) – Serialization type for the schema being registered.

  • schema_content (str) – String representation of the schema being registered.

Return type

SchemaProperties

Example:

Get schema by id.
schema_properties = await schema_registry_client.get_schema_id(schema_group, schema_name, serialization_type, schema_content)
schem_id = schema_properties.schema_id
async register_schema(schema_group: str, schema_name: str, serialization_type: str, schema_content: str, **kwargs: Any) → azure.schemaregistry._common._schema.SchemaProperties[source]

Register new schema. If schema of specified name does not exist in specified group, schema is created at version 1. If schema of specified name exists already in specified group, schema is created at latest version + 1.

Parameters
  • schema_group (str) – Schema group under which schema should be registered.

  • schema_name (str) – Name of schema being registered.

  • serialization_type (Union[str, SerializationType]) – Serialization type for the schema being registered. For now Avro is the only supported serialization type by the service.

  • schema_content (str) – String representation of the schema being registered.

Return type

SchemaProperties

Example:

Register a new schema.
SCHEMA_GROUP = os.environ['SCHEMA_REGISTRY_GROUP']
SCHEMA_NAME = 'your-schema-name'
SERIALIZATION_TYPE = SerializationType.AVRO
SCHEMA_CONTENT = """
{"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_properties = await schema_registry_client.register_schema(SCHEMA_GROUP, SCHEMA_NAME, SERIALIZATION_TYPE, SCHEMA_CONTENT)
schem_id = schema_properties.schema_id