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.3.0.tar.gz
(5.6 kB
view hashes)
Built Distribution
Close
Hashes for pydantic2avro-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de99582efa4ac045d7719d54f968d1979804dc17b49a2f5fc451031b6356328f |
|
MD5 | 7bf90fdf507944f3c1bf889589f744c8 |
|
BLAKE2b-256 | 695482bb235a78d4ff550756607b9410ec0d1a680b7e324432d29751abd3a958 |