pydantic2avro
Generate Apache Avro schemas from Pydantic data models.
Install
pip install pydantic2avro
Example
- Create a file
main.pywith:
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%.
Metadata
Release files for pydantic2avro 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic2avro-0.4.1.tar.gz | 5.6 kB | Without provenance | Details for pydantic2avro-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic2avro-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for pydantic2avro-0.4.1-py3-none-any.whl |
Total release size: 13.4 kB
Release files / pydantic2avro-0.4.1.tar.gz
| Download URL | pydantic2avro-0.4.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe719b153645e642903d5e9cf7dd9eb9c54ca951baa11d9a9b2e7e7fb4e915cb
|
|
BLAKE2b-256 checksum How to use checksums |
d68457e01a9dc1316f7389eb05e32a1d113da4891a841be5efdecf70f0decd77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.12.4 Linux/6.10.3-200.fc40.x86_64
|
Release files / pydantic2avro-0.4.1-py3-none-any.whl
| Download URL | pydantic2avro-0.4.1-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10266d50f86a9daac66b4d5c7730c57b713a0291f8fe0b23511cfe650c485c8b
|
|
BLAKE2b-256 checksum How to use checksums |
6b37b95c82264b77c09afaaf05a4cd020026df6aca4eea733f5e025da4abbbf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.12.4 Linux/6.10.3-200.fc40.x86_64
|
Security for pydantic2avro 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.