SchemaRegistryClient Class
SchemaRegistryClient is a client for registering and retrieving schemas from the Azure Schema Registry service.
- Inheritance
-
builtins.objectSchemaRegistryClient
Constructor
SchemaRegistryClient(fully_qualified_namespace: str, credential: TokenCredential, **kwargs: Any)
Parameters
- fully_qualified_namespace
- str
The Schema Registry service fully qualified host name. For example: my-namespace.servicebus.windows.net.
- credential
- TokenCredential
To authenticate managing the entities of the SchemaRegistry namespace.
- api_version
- str
The Schema Registry service API version to use for requests. Default value and only accepted value currently is "2021-10".
Examples
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
)
Methods
| close |
This method is to close the sockets opened by the client. It need not be used when using with a context manager. |
| get_schema |
Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace. |
| get_schema_properties |
Gets the schema properties corresponding to an existing schema within the specified schema group, as matched by schema definition comparison. |
| register_schema |
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. |
close
This method is to close the sockets opened by the client. It need not be used when using with a context manager.
close() -> None
get_schema
Gets a registered schema by its unique ID. Azure Schema Registry guarantees that ID is unique within a namespace.
get_schema(schema_id: str, **kwargs: Any) -> azure.schemaregistry._common._schema.Schema
Parameters
Return type
Exceptions
Examples
Get schema by id.
schema = schema_registry_client.get_schema(schema_id)
definition = schema.definition
properties = schema.properties
get_schema_properties
Gets the schema properties corresponding to an existing schema within the specified schema group, as matched by schema definition comparison.
get_schema_properties(group_name: str, name: str, definition: str, format: Union[str, azure.schemaregistry._common._constants.SchemaFormat], **kwargs: Any) -> azure.schemaregistry._common._schema.SchemaProperties
Parameters
- definition
- str
String representation of the schema for which properties should be retrieved.
- format
- <xref:Union>[str, SchemaFormat]
Format for the schema for which properties should be retrieved.
Return type
Exceptions
Examples
Get schema id.
group_name = os.environ["SCHEMAREGISTRY_GROUP"]
name = "your-schema-name"
format = "Avro"
schema_json = {
"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": ["int", "null"]},
{"name": "favorite_color", "type": ["string", "null"]},
],
}
definition = json.dumps(schema_json, separators=(",", ":"))
schema_properties = schema_registry_client.get_schema_properties(
group_name, name, definition, format
)
schema_id = schema_properties.id
register_schema
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.
register_schema(group_name: str, name: str, definition: str, format: Union[str, azure.schemaregistry._common._constants.SchemaFormat], **kwargs: Any) -> azure.schemaregistry._common._schema.SchemaProperties
Parameters
- format
- <xref:Union>[str, SchemaFormat]
Format for the schema being registered. For now Avro is the only supported schema format by the service.
Return type
Exceptions
Examples
Register a new schema.
GROUP_NAME = os.environ["SCHEMAREGISTRY_GROUP"]
NAME = "your-schema-name"
FORMAT = "Avro"
SCHEMA_JSON = {
"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": ["int", "null"]},
{"name": "favorite_color", "type": ["string", "null"]},
],
}
DEFINTION = json.dumps(SCHEMA_JSON, separators=(",", ":"))
schema_properties = schema_registry_client.register_schema(
GROUP_NAME, NAME, DEFINTION, FORMAT
)
schema_id = schema_properties.id
Feedback
Submit and view feedback for