Skip to main content

Faust serializer that serializes Avro compatible messages

Project description

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.

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

faust-avro-serializer-1.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

faust_avro_serializer-1.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file faust-avro-serializer-1.1.0.tar.gz.

File metadata

File hashes

Hashes for faust-avro-serializer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 73c0be487c37af3516fde8570ae0d6a8a7d8546b0d275dca2d8415e6cca448a2
MD5 e00e59b454adb9b11b455b67960ec3bd
BLAKE2b-256 c0ec9a3b1c5153cf1ffe5b3fe146423f8a0152dbb2f7470d6732c8d83198cafa

See more details on using hashes here.

File details

Details for the file faust_avro_serializer-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for faust_avro_serializer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ec4f697e3d88b2912299ae1397738f77154f048313c5d5b4b8d945d4c3fa040
MD5 1cced58b7a9a8e62d8a6b04f89e14baf
BLAKE2b-256 c7504a9a586bea0a8304a5c68c184c44f9d789b89bebb32a13ceb57766426323

See more details on using hashes here.

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