This library can convert a pydantic class to a avro schema or generate python code from a avro schema.
pip install pydantic-avro
import json
from typing import Optional
from pydantic_avro.base import AvroBase
class TestModel(AvroBase):
key1: str
key2: int
key2: Optional[str]
schema_dict: dict = TestModel.avro_schema()
print(json.dumps(schema_dict))
# Print to stdout
pydantic-avro avro_to_pydantic --avsc /path/to/schema.avsc
# Save it to a file
pydantic-avro avro_to_pydantic --avsc /path/to/schema.avsc --output /path/to/output.py
- Requirement: Poetry 1.*
poetry install
pytest
coverage run -m pytest # with coverage
# or (depends on your local env)
poetry run pytest
poetry run coverage run -m pytest # with coverage
The linting is checked in the github workflow. To fix and review issues run this:
black . # Auto fix all issues
isort . # Auto fix all issues
pflake . # Only display issues, fixing is manual