Skip to main content

faust-avro-serializer

This repo contains an improved version of the avro serializer from https://github.com/marcosschroh/python-schema-registry-client/. It expects the schema to be stored in the record itself in order to mimic the behavior of Confluent's Avro SerDe. It uses Faust's metadata capability inside the Record class to read the Avro schema dynamically.

Example

from faust import Record, Schema, Stream
from faust_avro_serializer import FaustAvroSerializer
from schema_registry.client import SchemaRegistryClient
import faust

app = faust.App('myapp', broker='kafka://localhost')
my_topic_name = "my-dummy-topic"

class MyRecordExample(Record):
    _schema = {
     "type": "record",
     "namespace": "com.example",
     "name": "MyRecordExample",
     "fields": [
       { "name": "foo", "type": "string" },
       { "name": "bar", "type": "string" }
     ]
} 
    foo: str
    bar: str

client = SchemaRegistryClient("http://my-schema-registry:8081")
serializer = FaustAvroSerializer(client, my_topic_name, False)

schema_with_avro = Schema(key_serializer=str, value_serializer=serializer)

dummy_topic = app.topic(my_topic_name, schema=schema_with_avro)

@app.agents(dummy_topic)
async def my_agent(myrecord: Stream[MyRecordExample]):
    async for record in myrecord:
        print(record.to_representation())

When the serializer calls the _dumps method, it searches for the __faust field inside the record. If the serializer finds the field, it is resolving the class and reads the _schema field containing the Avro schema.

Metadata

Release files for faust-avro-serializer 1.2.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 faust-avro-serializer 1.2.0
File Size Uploaded
faust_avro_serializer-1.2.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for faust-avro-serializer 1.2.0
File Interpreter ABI Platform
faust_avro_serializer-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / faust_avro_serializer-1.2.0.tar.gz

Download URL faust_avro_serializer-1.2.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0305bc6882c489b90c2651ec2363603a04c2e6c3a8f9021aca386538444d6d12
BLAKE2b-256 checksum
How to use checksums
226e8fc5d5f74006a4a936ac04ebc2d8ccee5e62d82b267dc5aaa7cc75638eb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / faust_avro_serializer-1.2.0-py3-none-any.whl

Download URL faust_avro_serializer-1.2.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cdb22b305cce3d8dabcd5686c62b4f3e5f08e863b9e0d7a0ca9ed532b84b5578
BLAKE2b-256 checksum
How to use checksums
6f786a2a1762c240c00a86c3d737da387fe4d21230c49e2a502045b7cc3499d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.1

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