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.10.0.tar.gz
(10.6 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.10.0.tar.gz.
File metadata
- Download URL: pydantic_avro-0.10.0.tar.gz
- Upload date:
- Size: 10.6 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 |
abf912bf77b110e1763d2e06c86e1b08eb991ba99143dcb76ebebf7e3a9c426a
|
|
| MD5 |
37ad8af9e95252ca6dff92f6259923e6
|
|
| BLAKE2b-256 |
15be2cbfe7469298f0e78a62162fe0858fdd9e83f5b7c7d1c283dd9f073fb1f5
|
File details
Details for the file pydantic_avro-0.10.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_avro-0.10.0-py3-none-any.whl
- Upload date:
- Size: 12.2 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 |
b06d24054236d2ea5e51cd1ea28ff0b78be9cb12bd38f8b6e60cd0ed164b528f
|
|
| MD5 |
c0a17298423f1262a3db57d85da122d1
|
|
| BLAKE2b-256 |
27c59ab3de2754b91d4f48ea871a8de15d6014b20db1bbcd31afc7e9ebd0d5f9
|