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

Uploaded Source

Built Distribution

pydantic_avro-0.7.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_avro-0.7.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.19 Linux/6.5.0-1021-azure

File hashes

Hashes for pydantic_avro-0.7.1.tar.gz
Algorithm Hash digest
SHA256 75b691cd82edf977a637c7e3aa8f6bd731c761b268e2800d7eaabf7b6e69c2cc
MD5 6f073a3353115c349acf092eccc0408a
BLAKE2b-256 d0a9518fc926a368090d2668115585f6a8a06da265bfa752da667080884e43d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydantic_avro-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.19 Linux/6.5.0-1021-azure

File hashes

Hashes for pydantic_avro-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 515058cd11a256b85e7b22c02ace87761392e8ca4eb0b7548663a69763b82170
MD5 684c8e88de1a458edcb972a99785bef8
BLAKE2b-256 2da357e991b6bbd555c70d684ba0803704ed5cc6a6e854f508aad0fd8c072512

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