Happy-Kunal / pydantic2avro

Generate Apache Avro schemas for Pydantic data models.
https://pypi.org/project/pydantic2avro/
MIT License
0 stars 0 forks source link
avro avro-schema kafka pydantic pydantic-v2 schema-registry

pydantic2avro

Generate Apache Avro schemas from Pydantic data models.

Install

pip install pydantic2avro

Example

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
```bash
$ 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
$ 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

TODO: