Converting pydantic classes to avro schemas
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydantic_avro-0.9.2.tar.gz
(10.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_avro-0.9.2.tar.gz.
File metadata
- Download URL: pydantic_avro-0.9.2.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.25 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c0cecf167ae51cf8ea255ee5d612be8f0e376d79ed73bcfc0175471722ffea6
|
|
| MD5 |
8ba0b1f37407d40542a5e11bb85d57b0
|
|
| BLAKE2b-256 |
71627a5b45fb0a9c6ed26bcc6747a7f4d1daf66e8a25957c19c5ba3ac0c6df05
|
File details
Details for the file pydantic_avro-0.9.2-py3-none-any.whl.
File metadata
- Download URL: pydantic_avro-0.9.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.25 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
097daa143e18c26b396cc1f32764e09e71c9cf372cf3a36503c8afee10fb63f6
|
|
| MD5 |
91163cb35c3124cb3e361e54b7a3aa7d
|
|
| BLAKE2b-256 |
1f58776c7c74655ca4829e7e5a00d5875066d25b31941a93eb9e4400763a9539
|