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.4.2.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file pydantic-avro-0.4.2.tar.gz
.
File metadata
- Download URL: pydantic-avro-0.4.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.1 Darwin/21.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa55146bdff1f480b1c51559b983d821b9f2184eca021d3232cfb52e73aa7c05 |
|
MD5 | f71f5fd306ad5ce88bcc5f709190fba3 |
|
BLAKE2b-256 | 390dbdb90dbf954a63202f2d6aa6b133018cf1781988d6513f4edfb3b80b25af |
File details
Details for the file pydantic_avro-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: pydantic_avro-0.4.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.1 Darwin/21.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c701478766fb4691077505bebd2d96e291a6676ed4aff100a4b79bf6ad5c5d7c |
|
MD5 | 7f0a1ffff7aab6faf2bf969dd006bfea |
|
BLAKE2b-256 | 274e17465c12ca8e04e7a509c450f464b707725bce6212ec7685ad4fea7dec99 |