A repo that allows for quick decode and encode.
Please read Avro Spec for how to create schema configuration.
Allows Decoding of byte steam with the schema provided. If the schema is incorrect an error may be raised.
from betacore.kafka.schema.avro import AvroSchema
message = {
"test": "body"
}
schema = {
"type": "record",
"namespace": "betacore",
"name": "Test entity",
"fields": [
{"name": "test", "type": "string"}
]
}
encoded: bytes = AvroSchema().encode(message, schema=schema)
actual: dict = AvroSchema().decode(encoded, schema=schema)
Sample on how to encode with an avro schema. The message keys must be in the schema definition
from betacore.kafka.schema.avro import AvroSchema
message = {
"test": "body"
}
schema = {
"type": "record",
"namespace": "betacore",
"name": "Test entity",
"fields": [
{"name": "test", "type": "string"}
]
}
encoded: bytes = AvroSchema().encode(message, schema=schema)
The registry is still in beta only get / decode operations are implemented. This functional may be broken.
- Clone repo
- if using python virtual environment, which is strongly recommended, source the
venv
script. - install packages
- Required:
pip3 install -r requirements.txt
- Development:
pip3 install -r requirements-dev.txt
- Required:
- run
make help
for list of commands you can run