Skip to content

Commit 2075653

Browse files
authored
[Schema Registry] bug bash docs (Azure#21457)
fixes: Azure#21177
1 parent c4a1d6e commit 2075653

File tree

13 files changed

+324
-203
lines changed

13 files changed

+324
-203
lines changed

sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# Release History
22

3-
## 1.0.0b4 (Unreleased)
3+
## 1.0.0 (Unreleased)
4+
5+
**Note:** This is the first stable release of our efforts to create a user-friendly and Pythonic client library for Azure Schema Registry.
46

57
### Features Added
68

9+
- `SchemaRegistryClient` is the top-level client class interacting with the Azure Schema Registry Service. It provides three methods:
10+
- `register_schema`: Store schema in the service by providing schema group name, schema name, schema format and schema definition.
11+
- `get_schema`: Get schema definition and its properties by schema id.
12+
- `get_schema_properties`: Get schema properties by providing schema group name, schema name, schema format and schema definition.
13+
- `SchemaProperties` has the following instance variables: `id`, `format`, `version`.
14+
- `Schema` has the following properties: `properties` and `schema_definition`.
15+
- `SchemaFormat` provides the schema format to be stored by the service. Currently, the only supported format is `Avro`.
16+
717
### Breaking Changes
818

919
### Bugs Fixed

sdk/schemaregistry/azure-schemaregistry/README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ _Azure SDK Python packages support for Python 2.7 is ending 01 January 2022. For
1414

1515
### Install the package
1616

17-
Install the Azure Schema Registry client library and Azure Identity client library for Python with [pip][pip]:
17+
Install the Azure Schema Registry client library for Python with [pip][pip]:
1818

1919
```Bash
20-
pip install azure-schemaregistry azure-identity
20+
pip install azure-schemaregistry
2121
```
2222

2323
### Prerequisites:
@@ -27,7 +27,23 @@ To use this package, you must have:
2727
* Python 2.7, 3.6 or later - [Install Python][python]
2828

2929
### Authenticate the client
30-
Interaction with Schema Registry starts with an instance of SchemaRegistryClient class. You need the fully qualified namespace and AAD credential to instantiate the client object.
30+
31+
Interaction with Schema Registry starts with an instance of SchemaRegistryClient class. The client constructor takes the fully qualified namespace and an Azure Active Directory credential:
32+
33+
* The fully qualified namespace of the Schema Registry instance should follow the format: `<yournamespace>.servicebus.windows.net`.
34+
35+
* An AAD credential that implements the [TokenCredential][token_credential_interface] protocol should be passed to the constructor. There are implementations of the `TokenCredential` protocol available in the
36+
[azure-identity package][pypi_azure_identity]. To use the credential types provided by `azure-identity`, please install the Azure Identity client library for Python with [pip][pip]:
37+
38+
```Bash
39+
pip install azure-identity
40+
```
41+
42+
* Additionally, to use the async API supported on Python 3.6+, you must first install an async transport, such as [aiohttp](https://pypi.org/project/aiohttp/):
43+
44+
```Bash
45+
pip install aiohttp
46+
```
3147

3248
**Create client using the azure-identity library:**
3349

@@ -43,7 +59,9 @@ schema_registry_client = SchemaRegistryClient(fully_qualified_namespace, credent
4359

4460
## Key concepts
4561

46-
- Schema: Schema is the organization or structure for data.
62+
- Schema: Schema is the organization or structure for data. More detailed information can be found [here][schemas].
63+
64+
- 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 found [here][schema_groups].
4765

4866
- SchemaRegistryClient: `SchemaRegistryClient` provides the API for storing and retrieving schemas in schema registry.
4967

@@ -67,8 +85,8 @@ from azure.schemaregistry import SchemaRegistryClient
6785

6886
token_credential = DefaultAzureCredential()
6987
fully_qualified_namespace = os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']
70-
group_name = "<your-group-name>"
71-
name = "<your-schema-name>"
88+
group_name = os.environ['SCHEMA_REGISTRY_GROUP']
89+
name = "your-schema-name"
7290
format = "Avro"
7391
schema_definition = """
7492
{"namespace": "example.avro",
@@ -90,7 +108,7 @@ with schema_registry_client:
90108

91109
### Get the schema by id
92110

93-
Get the schema content and its properties by schema id.
111+
Get the schema definition and its properties by schema id.
94112

95113
```python
96114
import os
@@ -100,7 +118,7 @@ from azure.schemaregistry import SchemaRegistryClient
100118

101119
token_credential = DefaultAzureCredential()
102120
fully_qualified_namespace = os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']
103-
id = '<your-schema-id>'
121+
id = 'your-schema-id'
104122

105123
schema_registry_client = SchemaRegistryClient(fully_qualified_namespace=fully_qualified_namespace, credential=token_credential)
106124
with schema_registry_client:
@@ -110,7 +128,7 @@ with schema_registry_client:
110128

111129
### Get the id of a schema
112130

113-
Get the schema id of a schema by schema content and its properties.
131+
Get the schema id of a schema by schema definition and its properties.
114132

115133
```python
116134
import os
@@ -120,8 +138,8 @@ from azure.schemaregistry import SchemaRegistryClient
120138

121139
token_credential = DefaultAzureCredential()
122140
fully_qualified_namespace = os.environ['SCHEMA_REGISTRY_FULLY_QUALIFIED_NAMESPACE']
123-
group_name = "<your-group-name>"
124-
name = "<your-schema-name>"
141+
group_name = os.environ['SCHEMA_REGISTRY_GROUP']
142+
name = "your-schema-name"
125143
format = "Avro"
126144
schema_definition = """
127145
{"namespace": "example.avro",
@@ -186,13 +204,6 @@ schema_registry_client.get_schema(id, logging_enable=True)
186204

187205
Please take a look at the [samples][sr_samples] directory for detailed examples of how to use this library to register and retrieve schema to/from Schema Registry.
188206

189-
### Event Hubs and Avro Serializer
190-
191-
We provide [azure-schemaregistry-avroserializer][schemaregistry_avroserializer_pypi] library as serializer
192-
implementation to serialize/deserialize avro data integrated with `azure-schemaregistry` for automatic schema registration and retrieval.
193-
It integrates nicely with the [EventHubs SDK][eventhubs_repo].
194-
For more information and sample codes, please refer to the [Azure Schema Registry Avro Serializer SDK][schemaregistry_avroserializer_repo].
195-
196207
## Contributing
197208

198209
This project welcomes contributions and suggestions. Most contributions require you to agree to a
@@ -215,10 +226,12 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
215226
[azure_sub]: https://azure.microsoft.com/free/
216227
[python_logging]: https://docs.python.org/3/library/logging.html
217228
[sr_samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry/samples
218-
[api_reference]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-schemaregistry/latest/index.html
229+
[api_reference]: https://docs.microsoft.com/python/api/overview/azure/schemaregistry-readme
219230
[source_code]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry
220231
[change_log]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md
232+
[schemas]: https://docs.microsoft.com/azure/event-hubs/schema-registry-overview#schemas
233+
[schema_groups]: https://docs.microsoft.com/azure/event-hubs/schema-registry-overview#schema-groups
221234
[schemaregistry_service]: https://aka.ms/schemaregistry
222-
[schemaregistry_avroserializer_repo]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry-avroserializer
223235
[schemaregistry_avroserializer_pypi]: https://pypi.org/project/azure-schemaregistry-avroserializer/
224-
[eventhubs_repo]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/eventhub/azure-eventhub
236+
[token_credential_interface]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core/azure/core/credentials.py
237+
[pypi_azure_identity]: https://pypi.org/project/azure-identity/

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_common/_constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@
2727

2828

2929
class SchemaFormat(str, Enum):
30+
"""
31+
Represents the format of the schema to be stored by the Schema Registry service.
32+
"""
33+
3034
AVRO = "avro"
35+
"""Represents the Apache Avro schema format."""

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_common/_schema.py

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,41 @@ class SchemaProperties(object):
3131
Meta properties of a schema.
3232
3333
:ivar id: References specific schema in registry namespace.
34-
:type id: str
34+
:vartype id: str
3535
:ivar format: Format for the schema being stored.
36-
:type format: str
36+
:vartype format: str
3737
:ivar version: Version of the returned schema.
38-
:type version: int
39-
40-
.. admonition:: Example:
41-
42-
.. literalinclude:: ../samples/sync_samples/sample_code_schemaregistry.py
43-
:start-after: [START print_schema_properties]
44-
:end-before: [END print_schema_properties]
45-
:language: python
46-
:dedent: 4
47-
:caption: SchemaProperties object.
48-
38+
:vartype version: int
4939
"""
5040

51-
def __init__(
52-
self,
53-
**kwargs
54-
):
41+
def __init__(self, **kwargs):
5542
# type: (Any) -> None
56-
self.id = kwargs.pop('id')
57-
self.format = kwargs.pop('format')
58-
self.version = kwargs.pop('version')
43+
self.id = kwargs.pop("id")
44+
self.format = kwargs.pop("format")
45+
self.version = kwargs.pop("version")
46+
47+
def __repr__(self):
48+
return "SchemaProperties(id={}, format={}, version={})".format(
49+
self.id, self.format, self.version
50+
)[:1024]
5951

6052

6153
class Schema(object):
6254
"""
6355
The schema content of a schema, along with id and meta properties.
6456
6557
:ivar schema_definition: The content of the schema.
66-
:type schema_definition: str
58+
:vartype schema_definition: str
6759
:ivar properties: The properties of the schema.
68-
:type properties: SchemaProperties
69-
70-
.. admonition:: Example:
71-
72-
.. literalinclude:: ../samples/sync_samples/sample_code_schemaregistry.py
73-
:start-after: [START print_schema]
74-
:end-before: [END print_schema]
75-
:language: python
76-
:dedent: 4
77-
:caption: Schema object.
78-
60+
:vartype properties: SchemaProperties
7961
"""
8062

81-
def __init__(
82-
self,
83-
**kwargs
84-
):
63+
def __init__(self, **kwargs):
8564
# type: (Any) -> None
8665
self.schema_definition = kwargs.pop("schema_definition")
8766
self.properties = kwargs.pop("properties")
67+
68+
def __repr__(self):
69+
return "Schema(schema_definition={}, properties={})".format(
70+
self.schema_definition, self.properties
71+
)[:1024]

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_schema_registry_client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141

4242
class SchemaRegistryClient(object):
4343
"""
44-
SchemaRegistryClient is as a central schema repository for enterprise-level data infrastructure,
45-
complete with support for versioning and management.
44+
SchemaRegistryClient is a client for registering and retrieving schemas from the Azure Schema Registry service.
4645
47-
:param str fully_qualified_namespace: The Schema Registry service fully qualified host name,
48-
for example my-namespace.servicebus.windows.net.
49-
:param credential: To authenticate to manage the entities of the SchemaRegistry namespace.
50-
:type credential: TokenCredential
46+
:param str fully_qualified_namespace: The Schema Registry service fully qualified host name.
47+
For example: my-namespace.servicebus.windows.net.
48+
:param credential: To authenticate managing the entities of the SchemaRegistry namespace.
49+
:type credential: ~azure.core.credentials.TokenCredential
5150
5251
.. admonition:: Example:
5352
@@ -97,7 +96,8 @@ def register_schema(
9796
:param format: Format for the schema being registered.
9897
For now Avro is the only supported schema format by the service.
9998
:type format: Union[str, SchemaFormat]
100-
:rtype: SchemaProperties
99+
:rtype: ~azure.schemaregistry.SchemaProperties
100+
:raises: :class:`~azure.core.exceptions.HttpResponseError`
101101
102102
.. admonition:: Example:
103103
@@ -134,7 +134,8 @@ def get_schema(self, id, **kwargs): # pylint:disable=redefined-builtin
134134
Azure Schema Registry guarantees that ID is unique within a namespace.
135135
136136
:param str id: References specific schema in registry namespace.
137-
:rtype: Schema
137+
:rtype: ~azure.schemaregistry.Schema
138+
:raises: :class:`~azure.core.exceptions.HttpResponseError`
138139
139140
.. admonition:: Example:
140141
@@ -156,15 +157,16 @@ def get_schema_properties(
156157
):
157158
# type: (str, str, str, Union[str, SchemaFormat], Any) -> SchemaProperties
158159
"""
159-
Gets the ID referencing an existing schema within the specified schema group,
160+
Gets the schema properties corresponding to an existing schema within the specified schema group,
160161
as matched by schema definition comparison.
161162
162163
:param str group_name: Schema group under which schema should be registered.
163164
:param str name: Name of schema being registered.
164165
:param str schema_definition: String representation of the schema being registered.
165166
:param format: Format for the schema being registered.
166167
:type format: Union[str, SchemaFormat]
167-
:rtype: SchemaProperties
168+
:rtype: ~azure.schemaregistry.SchemaProperties
169+
:raises: :class:`~azure.core.exceptions.HttpResponseError`
168170
169171
.. admonition:: Example:
170172

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
#
2525
# --------------------------------------------------------------------------
2626

27-
VERSION = "1.0.0b4"
27+
VERSION = "1.0.0"

sdk/schemaregistry/azure-schemaregistry/azure/schemaregistry/aio/_schema_registry_client_async.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141

4242
class SchemaRegistryClient(object):
4343
"""
44-
SchemaRegistryClient is as a central schema repository for enterprise-level data infrastructure,
45-
complete with support for versioning and management.
44+
SchemaRegistryClient is a client for registering and retrieving schemas from the Azure Schema Registry service.
4645
47-
:param str fully_qualified_namespace: The Schema Registry service fully qualified host name,
48-
for example my-namespace.servicebus.windows.net.
49-
:param credential: To authenticate to manage the entities of the SchemaRegistry namespace.
50-
:type credential: AsyncTokenCredential
46+
:param str fully_qualified_namespace: The Schema Registry service fully qualified host name.
47+
For example: my-namespace.servicebus.windows.net.
48+
:param credential: To authenticate managing the entities of the SchemaRegistry namespace.
49+
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
5150
5251
.. admonition:: Example:
5352
@@ -98,8 +97,9 @@ async def register_schema(
9897
:param str schema_definition: String representation of the schema being registered.
9998
:param format: Format for the schema being registered.
10099
For now Avro is the only supported schema format by the service.
101-
:type format: Union[str, SchemaFormat]
102-
:rtype: SchemaProperties
100+
:type format: Union[str, ~azure.schemaregistry.SchemaFormat]
101+
:rtype: ~azure.schemaregistry.SchemaProperties
102+
:raises: :class:`~azure.core.exceptions.HttpResponseError`
103103
104104
.. admonition:: Example:
105105
@@ -139,7 +139,8 @@ async def get_schema(
139139
Azure Schema Registry guarantees that ID is unique within a namespace.
140140
141141
:param str id: References specific schema in registry namespace.
142-
:rtype: Schema
142+
:rtype: ~azure.schemaregistry.Schema
143+
:raises: :class:`~azure.core.exceptions.HttpResponseError`
143144
144145
.. admonition:: Example:
145146
@@ -165,15 +166,16 @@ async def get_schema_properties(
165166
**kwargs: Any
166167
) -> SchemaProperties:
167168
"""
168-
Gets the ID referencing an existing schema within the specified schema group,
169+
Gets the schema properties corresponding to an existing schema within the specified schema group,
169170
as matched by schema defintion comparison.
170171
171172
:param str group_name: Schema group under which schema should be registered.
172173
:param str name: Name of schema being registered.
173174
:param str schema_definition: String representation of the schema being registered.
174175
:param format: Format for the schema being registered.
175-
:type format: Union[str, SchemaFormat]
176-
:rtype: SchemaProperties
176+
:type format: Union[str, ~azure.schemaregistry.SchemaFormat]
177+
:rtype: ~azure.schemaregistry.SchemaProperties
178+
:raises: :class:`~azure.core.exceptions.HttpResponseError`
177179
178180
.. admonition:: Example:
179181

sdk/schemaregistry/azure-schemaregistry/samples/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ If you do not have an existing Azure account, you may sign up for a free trial o
3131
1. Install the Azure Schema Registry client library and Azure Identity client library for Python with [pip](https://pypi.org/project/pip/):
3232

3333
```bash
34-
pip install azure-schemaregistry azure-identity
34+
pip install azure-schemaregistry
3535
```
3636

37-
2. Clone or download this sample repository
37+
To run samples utilizing the Azure Active Directory for authentication, please install the azure-identity library:
38+
39+
```bash
40+
pip install azure-identity
41+
```
42+
43+
2. Clone or download this sample repository.
3844
3. Open the sample folder in Visual Studio Code or your IDE of choice.
3945

4046
## Running the samples
@@ -51,4 +57,4 @@ what you can do with the Azure Schema Registry client library.
5157
<!-- LINKS -->
5258
[schema_registry_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry/samples/sync_samples/schema_registry.py
5359
[schema_registry_async_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry/samples/async_samples/schema_registry_async.py
54-
[api_reference]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-schemaregistry/latest/index.html
60+
[api_reference]: https://docs.microsoft.com/python/api/overview/azure/schemaregistry-readme

0 commit comments

Comments
 (0)