@@ -3,19 +3,19 @@ title: Azure Schema Registry Avro Encoder client library for Python
3
3
keywords : Azure, python, SDK, API, azure-schemaregistry-avroencoder, schemaregistry
4
4
author : yunhaoling
5
5
ms.author : yuling
6
- ms.date : 02/10 /2022
6
+ ms.date : 03/09 /2022
7
7
ms.topic : reference
8
8
ms.prod : azure
9
9
ms.technology : azure
10
10
ms.devlang : python
11
11
ms.service : schemaregistry
12
12
---
13
- # Azure Schema Registry Avro Encoder client library for Python - Version 1.0.0b1
13
+ # Azure Schema Registry Avro Encoder client library for Python - Version 1.0.0b2
14
14
15
15
16
16
Azure Schema Registry is a schema repository service hosted by Azure Event Hubs, providing schema storage, versioning,
17
17
and management. This package provides an Avro encoder capable of encoding and decoding payloads containing
18
- Schema Registry schema identifiers and Avro-encoded data .
18
+ Schema Registry schema identifiers and Avro-encoded content .
19
19
20
20
[ Source code] [ source_code ] | [ Package (PyPi)] [ pypi ] | [ API reference documentation] [ api_reference ] | [ Samples] [ sr_avro_samples ] | [ Changelog] [ change_log ]
21
21
@@ -83,13 +83,13 @@ content type with schema ID. Uses [SchemaRegistryClient][schemaregistry_client]
83
83
84
84
Support has been added to certain Azure Messaging SDK model classes for interoperability with the ` AvroEncoder ` . These models are subtypes of the ` MessageType ` protocol defined under the ` azure.schemaregistry.encoder.avroencoder ` namespace. Currently, the supported model classes are:
85
85
86
- - ` azure.eventhub.EventData ` for ` azure-eventhub==5.9.0b1 `
86
+ - ` azure.eventhub.EventData ` for ` azure-eventhub==5.9.0b2 `
87
87
88
88
### Message format
89
89
90
- If a message type that follows the MessageType protocol is provided to the encoder, it will encode the corresponding data and content type properties as follows:
90
+ If a message type that follows the MessageType protocol is provided to the encoder, it will encode the corresponding content and content type properties as follows:
91
91
92
- - ` data ` : Avro payload (in general, format-specific payload)
92
+ - ` content ` : Avro payload (in general, format-specific payload)
93
93
- Avro Binary Encoding
94
94
- NOT Avro Object Container File, which includes the schema and defeats the
95
95
purpose of this encoder to move the schema out of the message payload and
@@ -100,7 +100,7 @@ If a message type that follows the MessageType protocol is provided to the encod
100
100
- ` <schema ID> ` is the hexadecimal representation of GUID, same format and byte order as the string from the Schema Registry service.
101
101
102
102
If message type or callback function is not provided, and by default, the encoder will create the following dict:
103
- ` {"data ": <Avro encoded payload>, "content_type": 'avro/binary+<schema ID>' } `
103
+ ` {"content ": <Avro encoded payload>, "content_type": 'avro/binary+<schema ID>' } `
104
104
105
105
## Examples
106
106
@@ -113,7 +113,7 @@ The following sections provide several code snippets covering some of the most c
113
113
114
114
### Encoding
115
115
116
- Use ` AvroEncoder.encode ` method to encode dict data with the given Avro schema.
116
+ Use ` AvroEncoder.encode ` method to encode dict content with the given Avro schema.
117
117
The method will use a schema previously registered to the Schema Registry service and keep the schema cached for future encoding usage. It is also possible to avoid pre-registering the schema to the service and automatically register with the ` encode ` method by instantiating the ` AvroEncoder ` with the keyword argument ` auto_register_schemas=True ` .
118
118
119
119
``` python
@@ -145,20 +145,20 @@ schema_register_client.register(group_name, name, definition, format)
145
145
encoder = AvroEncoder(client = schema_registry_client, group_name = group_name)
146
146
147
147
with encoder:
148
- dict_data = {" name" : " Ben" , " favorite_number" : 7 , " favorite_color" : " red" }
149
- event_data = encoder.encode(dict_data , schema = definition, message_type = EventData)
148
+ dict_content = {" name" : " Ben" , " favorite_number" : 7 , " favorite_color" : " red" }
149
+ event_data = encoder.encode(dict_content , schema = definition, message_type = EventData)
150
150
151
151
# OR
152
152
153
- metadata_dict = encoder.encode(dict_data , schema = definition)
154
- event_data = EventData.from_message_data(metadata_dict[ " data " ], metadata_dict [" content_type" ])
153
+ message_content_dict = encoder.encode(dict_content , schema = definition)
154
+ event_data = EventData.from_message_content(message_content_dict[ " content " ], message_content_dict [" content_type" ])
155
155
```
156
156
157
157
### Decoding
158
158
159
- Use ` AvroEncoder.decode ` method to decode the bytes value into dict data by either:
159
+ Use ` AvroEncoder.decode ` method to decode the bytes value into dict content by either:
160
160
- Passing in a message object that is a subtype of the MessageType protocol.
161
- - Passing in a dict with keys ` data ` (type bytes) and ` content_type ` (type string).
161
+ - Passing in a dict with keys ` content ` (type bytes) and ` content_type ` (type string).
162
162
The method automatically retrieves the schema from the Schema Registry Service and keeps the schema cached for future decoding usage.
163
163
164
164
``` python
@@ -176,19 +176,19 @@ encoder = AvroEncoder(client=schema_registry_client, group_name=group_name)
176
176
177
177
with encoder:
178
178
# event_data is an EventData object with Avro encoded body
179
- decoded_data = encoder.decode(event_data)
179
+ decoded_content = encoder.decode(event_data)
180
180
181
181
# OR
182
182
183
- encoded_bytes = b ' <data_encoded_by_azure_schema_registry_avro_encoder >'
183
+ encoded_bytes = b ' <content_encoded_by_azure_schema_registry_avro_encoder >'
184
184
content_type = ' avro/binary+<schema_id_of_corresponding_schema>'
185
- data_dict = {" data " : encoded_bytes, " content_type" : content_type}
186
- decoded_data = encoder.decode(data_dict )
185
+ content_dict = {" content " : encoded_bytes, " content_type" : content_type}
186
+ decoded_content = encoder.decode(content_dict )
187
187
```
188
188
189
189
### Event Hubs Sending Integration
190
190
191
- Integration with [ Event Hubs] [ eventhubs_repo ] to send encoded Avro dict data as the body of EventData.
191
+ Integration with [ Event Hubs] [ eventhubs_repo ] to send encoded Avro dict content as the body of EventData.
192
192
193
193
``` python
194
194
import os
@@ -224,15 +224,15 @@ eventhub_producer = EventHubProducerClient.from_connection_string(
224
224
225
225
with eventhub_producer, avro_encoder:
226
226
event_data_batch = eventhub_producer.create_batch()
227
- dict_data = {" name" : " Bob" , " favorite_number" : 7 , " favorite_color" : " red" }
228
- event_data = avro_encoder.encode(dict_data , schema = definition, message_type = EventData)
227
+ dict_content = {" name" : " Bob" , " favorite_number" : 7 , " favorite_color" : " red" }
228
+ event_data = avro_encoder.encode(dict_content , schema = definition, message_type = EventData)
229
229
event_data_batch.add(event_data)
230
230
eventhub_producer.send_batch(event_data_batch)
231
231
```
232
232
233
233
### Event Hubs Receiving Integration
234
234
235
- Integration with [ Event Hubs] [ eventhubs_repo ] to receive ` EventData ` and decoded raw bytes into Avro dict data .
235
+ Integration with [ Event Hubs] [ eventhubs_repo ] to receive ` EventData ` and decoded raw bytes into Avro dict content .
236
236
237
237
``` python
238
238
import os
@@ -257,7 +257,7 @@ eventhub_consumer = EventHubConsumerClient.from_connection_string(
257
257
)
258
258
259
259
def on_event (partition_context , event ):
260
- decoded_data = avro_encoder.decode(event)
260
+ decoded_content = avro_encoder.decode(event)
261
261
262
262
with eventhub_consumer, avro_encoder:
263
263
eventhub_consumer.receive(on_event = on_event, starting_position = " -1" )
@@ -301,7 +301,7 @@ encoder = AvroEncoder(client=schema_registry_client, group_name="<your-group-nam
301
301
Similarly, ` logging_enable ` can enable detailed logging for a single operation,
302
302
even when it isn't enabled for the client:
303
303
``` py
304
- encoder.encode(dict_data , schema = schema_definition, logging_enable = True )
304
+ encoder.encode(dict_content , schema = schema_definition, logging_enable = True )
305
305
```
306
306
307
307
## Next steps
326
326
327
327
<!-- LINKS -->
328
328
[ pip ] : https://pypi.org/project/pip/
329
- [ pypi ] : https://pypi.org/
329
+ [ pypi ] : https://pypi.org/project/azure-schemaregistry-avroencoder/
330
330
[ python ] : https://www.python.org/downloads/
331
- [ azure_core ] : https://github.com/Azure/azure-sdk-for-python/blob/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/core/azure-core/README.md
331
+ [ azure_core ] : https://github.com/Azure/azure-sdk-for-python/blob/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/core/azure-core/README.md
332
332
[ azure_sub ] : https://azure.microsoft.com/free/
333
333
[ python_logging ] : https://docs.python.org/3/library/logging.html
334
- [ sr_avro_samples ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/schemaregistry/azure-schemaregistry-avroencoder/samples
335
- [ api_reference ] : https://docs.microsoft.com/python/api/
336
- [ source_code ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/schemaregistry/azure-schemaregistry-avroencoder
337
- [ change_log ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/schemaregistry/azure-schemaregistry-avroencoder/CHANGELOG.md
338
- [ schemaregistry_client ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/schemaregistry/azure-schemaregistry
334
+ [ sr_avro_samples ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/schemaregistry/azure-schemaregistry-avroencoder/samples
335
+ [ api_reference ] : https://docs.microsoft.com/python/api/overview/azure/schemaregistry-avroencoder-readme
336
+ [ source_code ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/schemaregistry/azure-schemaregistry-avroencoder
337
+ [ change_log ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/schemaregistry/azure-schemaregistry-avroencoder/CHANGELOG.md
338
+ [ schemaregistry_client ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/schemaregistry/azure-schemaregistry
339
339
[ schemaregistry_service ] : https://aka.ms/schemaregistry
340
- [ eventhubs_repo ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/eventhub/azure-eventhub
341
- [ token_credential_interface ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b1 /sdk/core/azure-core/azure/core/credentials.py
340
+ [ eventhubs_repo ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/eventhub/azure-eventhub
341
+ [ token_credential_interface ] : https://github.com/Azure/azure-sdk-for-python/tree/azure-schemaregistry-avroencoder_1.0.0b2 /sdk/core/azure-core/azure/core/credentials.py
342
342
[ pypi_azure_identity ] : https://pypi.org/project/azure-identity/
0 commit comments