Skip to main content

Generate Apache Avro schemas for Pydantic data models.

Project description

pydantic2avro

Generate Apache Avro schemas from Pydantic data models.

Install

pip install pydantic2avro

Example

  • Create a file main.py with:
from pprint import pprint
from uuid import UUID

from pydantic import BaseModel
from pydantic2avro import PydanticToAvroSchemaMaker


class User(BaseModel):
    id: UUID
    name: str
    age: int

schema = PydanticToAvroSchemaMaker(User).get_schema()
pprint(schema)
  • Run it
$ python main.py 
{'fields': [{'name': 'id', 'type': {'logicalType': 'uuid', 'type': 'string'}},
            {'name': 'name', 'type': 'string'},
            {'name': 'age', 'type': 'long'}],
 'name': 'User',
 'type': 'record'}
$

Developing

Install package
  • Requirement: Poetry 1.*
$ git clone https://github.com/Happy-Kunal/pydantic2avro
$ cd pydantic2avro/
$ 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

Features

  • Primitive types: int, long, double, float, boolean, string and null support
  • Complex types: enum, array, map, fixed, unions and records support
  • Logical Types: date, duration, time (millis and micro), datetime (millis and micro), uuid support
  • Recursive Schemas
  • Generate json from pydantic class instance

TODO:

  • write better tests.
  • increase test coverage from 92% to atleast 99%.

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

pydantic2avro-0.4.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

pydantic2avro-0.4.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file pydantic2avro-0.4.0.tar.gz.

File metadata

  • Download URL: pydantic2avro-0.4.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.4 Linux/6.9.8-200.fc40.x86_64

File hashes

Hashes for pydantic2avro-0.4.0.tar.gz
Algorithm Hash digest
SHA256 229b76e483b837f40bd28259f90ab3f85971c73105b9966baa178907ae87813c
MD5 a1d7e56073aff1d61628922b38137390
BLAKE2b-256 e30ab29f7146f25425e28d7c01cbbd907b72f399f87e3f43f0cc910029c3e104

See more details on using hashes here.

Provenance

File details

Details for the file pydantic2avro-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic2avro-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.1 CPython/3.12.4 Linux/6.9.8-200.fc40.x86_64

File hashes

Hashes for pydantic2avro-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20310fffb2f343683bfd68e69cd9428f967bb2a9a422e08801857cab47e456a4
MD5 3353067268277b2c2c3676fde2f490e2
BLAKE2b-256 17dcbd9b57f63996e3c390a2aa98b98e35af7aa7d6db1926265c10db8a9f9152

See more details on using hashes here.

Provenance

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