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.3.tar.gz
(10.2 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.3.tar.gz.
File metadata
- Download URL: pydantic_avro-0.9.3.tar.gz
- Upload date:
- Size: 10.2 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 |
9ec6558dacd7dac94f13f6f4edfdbb371bda000ff375399846b1165fd231e09c
|
|
| MD5 |
a3bc32deafb4047a14baf717ec3f8d3b
|
|
| BLAKE2b-256 |
65e3e854c7d9fa943eae692f61eaebef50169f44ff91bacd181ac1f9b5e8b4b3
|
File details
Details for the file pydantic_avro-0.9.3-py3-none-any.whl.
File metadata
- Download URL: pydantic_avro-0.9.3-py3-none-any.whl
- Upload date:
- Size: 11.7 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 |
3cfecf5f6ae782647d5fbb1e2783eba204a7db829674d82b8e8e45f4475f693f
|
|
| MD5 |
c6e9e30c23bff1d18300593ba65cba0b
|
|
| BLAKE2b-256 |
2e64de7f2a742d9fed4fb99745ac593ba3b311a67f528b5198a0c81428be3aac
|