pydantic-avro
This library can convert a pydantic class to a avro schema or generate python code from a avro schema.
Install
pip install pydantic-avro
Pydantic class to avro schema
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))
Avro schema to pydantic
# Print to stdout
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc
# Save it to a file
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py
Specify expected Avro type
from datetime import datetime
from pydantic import Field
from pydantic_avro.base import AvroBase
class ExampleModel(AvroBase):
field1: int = Field(..., avro_type="long") # Explicitly set Avro type to "long"
field2: datetime = Field(..., avro_type="timestamp-millis") # Explicitly set Avro type to "timestamp-millis"
Install for developers
Install package
- Requirement: Poetry 1.*
poetry install
Run unit tests
pytest
coverage run -m pytest # with coverage
# or (depends on your local env)
poetry run pytest
poetry run coverage run -m pytest # with coverage
Run linting
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
Metadata
Release files for pydantic-avro 0.12.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydantic_avro-0.12.1.tar.gz | 10.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_avro-0.12.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.6 kB
Release files / pydantic_avro-0.12.1.tar.gz
| Download URL | pydantic_avro-0.12.1.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bb33eb38036e1d27410c38db750de60e6476fa489b0fd7f4560a9b8ec2b8938
|
|
BLAKE2b-256 checksum How to use checksums |
b93fba243829bc2b761342ee65138c5f95ecde0f1185be338557326627e873a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pydantic_avro-0.12.1-py3-none-any.whl
| Download URL | pydantic_avro-0.12.1-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e6cdb3f50a64c063388cf2fa19ad2ad12c73b8e8a5ca8d67efdef8b8a903dc4
|
|
BLAKE2b-256 checksum How to use checksums |
b48ee1e00d55678472a2485fc7c22ac5c7160987101f1c17e1e4486191060d4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|