An Avro SerDe implementation that integrates with the confluent
Project description
confluent-avro
An Avro SerDe implementation that integrates with the confluent schema registry and serializes and deserializes data according to the defined confluent wire format
Installation
pip install confluent-avro
Usage:
Check examples for a full working demo.
Consumer App Example:
from kafka import KafkaConsumer
from confluent_avro.schema_registry import SchemaRegistry
from confluent_avro.schema_registry.auth import RegistryHTTPBasicAuth
from confluent_avro.serde import AvroKeyValueSerde
KAFKA_TOPIC = "confluent_avro-example-topic"
registry_client = SchemaRegistry(
"https://myschemaregistry.com",
RegistryHTTPBasicAuth("username", "password"),
headers={"Content-Type": "application/vnd.schemaregistry.v1+json"},
)
avroSerde = AvroKeyValueSerde(registry_client, KAFKA_TOPIC)
consumer = KafkaConsumer(
KAFKA_TOPIC,
group_id="random_group_id",
bootstrap_servers=["localhost:9092",]
)
for msg in consumer:
v = avroSerde.value.deserialize(msg.value)
k = avroSerde.key.deserialize(msg.key)
print(msg.offset, msg.partition, k, v)
Producer App Example:
from kafka import KafkaProducer
from confluent_avro.schema_registry import SchemaRegistry
from confluent_avro.schema_registry.auth import RegistryHTTPBasicAuth
from confluent_avro.serde import AvroKeyValueSerde
KAFKA_TOPIC = "confluent_avro-example-topic"
registry_client = SchemaRegistry(
"https://myschemaregistry.com",
RegistryHTTPBasicAuth("username", "password"),
headers={"Content-Type": "application/vnd.schemaregistry.v1+json"},
)
avroSerde = AvroKeyValueSerde(registry_client, KAFKA_TOPIC)
producer = KafkaProducer(bootstrap_servers=["localhost:9092"])
producer.send(
KAFKA_TOPIC,
key=avroSerde.key.serialize({...}, key_schema),
value=avroSerde.value.serialize({...}, value_schema),
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
confluent_avro-1.5.0.tar.gz
(16.9 kB
view hashes)
Built Distribution
Close
Hashes for confluent_avro-1.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bffb1d2023dc0a78e97982f303d6326267413047500ace45b124aba4db83dd3d |
|
MD5 | b82288aeae8e02fb1afa05719120b648 |
|
BLAKE2b-256 | 160cbefa7bdf05d8f3759438ee83d5e5fdaf98bb7fcddaf172cdd9372351a8e0 |