Skip to main content

Generate Apache Avro schemas for Pydantic data models.

Project description

pydantic2avro

Generate Apache Avro schemas for 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

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

Uploaded Source

Built Distribution

pydantic2avro-0.1.2-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

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