Skip to main content

An Avro SerDe implementation that integrates with the confluent

Project description

confluent-avro

PyPI - Python Version Build Status Maintainability codecov PyPI version PyPI - License

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)

Uploaded Source

Built Distribution

confluent_avro-1.5.0-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page