Skip to main content

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


ConfluentAvro

An Avro SerDe implementation that integrates with the confluent schema registry and serializes and deserializes data according to the defined confluent wire format.

View Demo · Report Bug · Request Feature

Getting Started

Background

To solve schema management issues and ensure compatibility in the development of Kafka-based applications, the confluent team introduced the schema registry to store and share the schema between the different apps and apply compatibility checks on each newly registered schema. To make the schema sharing easy, they extend the Avro binary format by prepending the schema id before the actual record instead of including the full schema.

-» You can find more about Confluent and Schema Registry in Confluent documentation.

Implementation

ConfluentAvro implemented according to the above specification. Before publishing to Kafka topic, the library prepends the schema id to the generated Avro binary and when consuming from Kafka, it retrieves the schema id and fetches the schema from the registry before deserializing the actual data.

The underline API will automatically register new schemas used for the data serialization and will fetch the corresponding schema when deserializing it. Newly registered schemas and fetched schemas are both cached locally to speed up the process for future records.

» The ConfluentAvro's bullet points:

  • Supports the confluent wire format
  • Integrates with the confluent schema registry
  • Retries with exponential backoff if connection to registry failed
  • Implements caching at the schema registry level
  • The underline decoder/encoder is built once for the same schema and reused for all upcoming records
  • Can be integrated with different Kafka clients

Built With

Installation

» pip install confluent-avro

Usage

Check examples for a fully working demo.

Consumer App Example:
from kafka import KafkaConsumer

from confluent_avro import AvroKeyValueSerde, SchemaRegistry
from confluent_avro.schema_registry import HTTPBasicAuth

KAFKA_TOPIC = "confluent_avro-example-topic"

registry_client = SchemaRegistry(
    "https://myschemaregistry.com",
    HTTPBasicAuth("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 import AvroKeyValueSerde, SchemaRegistry
from confluent_avro.schema_registry import HTTPBasicAuth

KAFKA_TOPIC = "confluent_avro-example-topic"

registry_client = SchemaRegistry(
    "https://myschemaregistry.com",
    HTTPBasicAuth("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),
)

Metadata

Release files for confluent_avro 1.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for confluent_avro 1.8.0
File Size Uploaded
confluent_avro-1.8.0.tar.gz 18.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for confluent_avro 1.8.0
File Interpreter ABI Platform
confluent_avro-1.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.1 kB

Release files / confluent_avro-1.8.0.tar.gz

Download URL confluent_avro-1.8.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2928da95009cebc9532c8e7af0c4b16add314e1e5542daeb297932bd2338ef86
BLAKE2b-256 checksum
How to use checksums
f9d4c125703c80b1afeeec8310e872cd21b4f743ee9bd642f349c843db479a89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.23.0

Release files / confluent_avro-1.8.0-py3-none-any.whl

Download URL confluent_avro-1.8.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37d7eafb975219a655c41ee2b95cb2fab030ff11d5af6773a6b9166e84591bfd
BLAKE2b-256 checksum
How to use checksums
b9d2d6fb2595c6997f1e4c289de457f8f12582a60789e366c3b3c43d7ae97ee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.23.0

Release history Release notifications | RSS feed

This release

1.8.0 This release

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page