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
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.6.2.tar.gz
(6.4 kB
view details)
Built Distribution
File details
Details for the file pydantic_avro-0.6.2.tar.gz
.
File metadata
- Download URL: pydantic_avro-0.6.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.17 Linux/5.15.0-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26dac864c82329dd486dcb5de9e6bbf9606668b0665546003af80a563db4bccb |
|
MD5 | b9c3147c53b159e665e75ddd97d049fb |
|
BLAKE2b-256 | 0fac4a9b58389c3431953a51a047a2658f1a909df504705d840ba2044a20dd8d |
File details
Details for the file pydantic_avro-0.6.2-py3-none-any.whl
.
File metadata
- Download URL: pydantic_avro-0.6.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.17 Linux/5.15.0-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb054aaa93ddb2de8df6892b4451e1f91efbefc18c7c0d769cc746b7183ad06a |
|
MD5 | 91b99129ef51ed73fb17a86c9b311b63 |
|
BLAKE2b-256 | bd6e2c190905ac9858d3b812359323b350cf523c789c864fb8b5edb5160cb76a |