azure.schemaregistry package

class azure.schemaregistry.Schema(**kwargs: Any)[source]

The schema content of a schema, along with id and meta properties.

Variables
  • schema_definition – The content of the schema.

  • properties – The properties of the schema.

Example:

Schema object.
print(schema.schema_definition)
print(schema.properties)
class azure.schemaregistry.SchemaFormat(value)[source]

An enumeration.

AVRO = 'avro'
class azure.schemaregistry.SchemaProperties(**kwargs: Any)[source]

Meta properties of a schema.

Variables
  • id – References specific schema in registry namespace.

  • format – Format for the schema being stored.

  • version – Version of the returned schema.

Example:

SchemaProperties object.
print(schema_properties.id)
print(schema_properties.format)
print(schema_properties.version)
class azure.schemaregistry.SchemaRegistryClient(fully_qualified_namespace: str, credential: TokenCredential, **kwargs: Any)[source]

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

Parameters
  • fully_qualified_namespace (str) – The Schema Registry service fully qualified host name, for example my-namespace.servicebus.windows.net.

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

Example:

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

get_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

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

Return type

Schema

Example:

Get schema by id.
schema = schema_registry_client.get_schema(id)
schema_definition = schema.schema_definition
get_schema_properties(group_name: str, name: str, schema_definition: str, format: 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 definition comparison.

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

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

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

  • format (Union[str, SchemaFormat]) – Format for the schema being registered.

Return type

SchemaProperties

Example:

Get schema id.
schema_properties = schema_registry_client.get_schema_properties(group_name, name, schema_definition, format)
schema_id = schema_properties.id
register_schema(group_name: str, name: str, schema_definition: str, format: 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
  • group_name (str) – Schema group under which schema should be registered.

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

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

  • format (Union[str, SchemaFormat]) – Format for the schema being registered. For now Avro is the only supported schema format by the service.

Return type

SchemaProperties

Example:

Register a new schema.
GROUP_NAME = os.environ['SCHEMAREGISTRY_GROUP']
NAME = 'your-schema-name'
FORMAT = SchemaFormat.AVRO
SCHEMA_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_properties = schema_registry_client.register_schema(GROUP_NAME, NAME, SCHEMA_DEFINITION, FORMAT)
schema_id = schema_properties.id