Skip to main content

Converting pydantic classes to avro schemas

Project description

Python package codecov PyPI version CodeQL

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


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.5.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

pydantic_avro-0.5.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_avro-0.5.1.tar.gz.

File metadata

  • Download URL: pydantic_avro-0.5.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Darwin/22.3.0

File hashes

Hashes for pydantic_avro-0.5.1.tar.gz
Algorithm Hash digest
SHA256 c5fbab63444ce10f6ce0a8453a8141d5b53759f012b383466ef4ca485c28fd6b
MD5 097abaa1650bbdb31588690bf62514ca
BLAKE2b-256 8d7b090b609cd705d56910690ae4822fa3467ee934cdda9bb7ccd4ffb3fec131

See more details on using hashes here.

File details

Details for the file pydantic_avro-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: pydantic_avro-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Darwin/22.3.0

File hashes

Hashes for pydantic_avro-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0114195151e511bc32346db782c783990f7ba0c64c1cfec8dc72a3f566a3d529
MD5 efe4dc3e0317f44e9ef8e818f3fbeeb6
BLAKE2b-256 0c6cc2375febea48e6a2fa50e0b0b64b62d53fc682a9919b3635e04078a95992

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page