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.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic_avro-0.13.0.tar.gz | 10.8 kB | Without provenance | Details for pydantic_avro-0.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_avro-0.13.0-py3-none-any.whl | Python 3 | none | any | Details for pydantic_avro-0.13.0-py3-none-any.whl |
Total release size: 23.6 kB
Release files / pydantic_avro-0.13.0.tar.gz
| Download URL | pydantic_avro-0.13.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31f837292d986740798acff73ebca3416175ad53c77d71ee034138f468faac32
|
|
BLAKE2b-256 checksum How to use checksums |
a625ba4221f4800c3e1ec73380766773ba1a689de4939fa7fc5f5a793eecc876
|
| 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.13.0-py3-none-any.whl
| Download URL | pydantic_avro-0.13.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c7495ef5cd80639ed06e68d469a981aa338b612769a109b2017b9d88141cbc0
|
|
BLAKE2b-256 checksum How to use checksums |
6427426e05cf5ab4e6c62c87f641323fd89c2b44e307f631e97fd61604516bfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for pydantic-avro 0.13.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.