# pydantic2avro
Generate Apache Avro schemas from Pydantic data models.
### Install
```bash
pip install pydantic2avro
```
### Example
* Create a file `main.py` with:
```python
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
```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
- Requirement: Poetry 1.*
```shell
$ git clone https://github.com/Happy-Kunal/pydantic2avro
$ cd pydantic2avro/
$ poetry install
```
###### Run unit tests
```shell
$ 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
- [x] Primitive types: int, long, double, float, boolean, string and null support
- [x] Complex types: enum, array, map, fixed, unions and records support
- [x] Logical Types: date, duration, time (millis and micro), datetime (millis and micro), uuid support
- [x] Recursive Schemas
- [x] Generate json from pydantic class instance
### TODO:
- [ ] write better tests.
- [ ] increase test coverage from 92% to atleast 99%.
Raw data
{
"_id": null,
"home_page": "https://github.com/Happy-Kunal/pydantic2avro",
"name": "pydantic2avro",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "pydantic, avro, kafka, messaging, schema, serialization, python",
"author": "Kunal Sharma",
"author_email": "happykunal@proton.me",
"download_url": "https://files.pythonhosted.org/packages/d6/84/57e01a9dc1316f7389eb05e32a1d113da4891a841be5efdecf70f0decd77/pydantic2avro-0.4.1.tar.gz",
"platform": null,
"description": "# pydantic2avro\nGenerate Apache Avro schemas from Pydantic data models. \n\n\n### Install\n\n```bash\npip install pydantic2avro\n```\n\n### Example\n\n* Create a file `main.py` with:\n```python\nfrom pprint import pprint\nfrom uuid import UUID\n\nfrom pydantic import BaseModel\nfrom pydantic2avro import PydanticToAvroSchemaMaker\n\n\nclass User(BaseModel):\n id: UUID\n name: str\n age: int\n\nschema = PydanticToAvroSchemaMaker(User).get_schema()\npprint(schema)\n\n```\n\n* Run it\n```bash\n$ python main.py \n{'fields': [{'name': 'id', 'type': {'logicalType': 'uuid', 'type': 'string'}},\n {'name': 'name', 'type': 'string'},\n {'name': 'age', 'type': 'long'}],\n 'name': 'User',\n 'type': 'record'}\n$\n```\n\n### Developing\n\n###### Install package\n\n- Requirement: Poetry 1.*\n\n```shell\n$ git clone https://github.com/Happy-Kunal/pydantic2avro\n$ cd pydantic2avro/\n$ poetry install\n```\n\n###### Run unit tests\n```shell\n$ pytest\n$ coverage run -m pytest # with coverage\n\n# or (depends on your local env) \n$ poetry run pytest\n$ poetry run coverage run -m pytest # with coverage\n```\n\n### Features\n- [x] Primitive types: int, long, double, float, boolean, string and null support\n- [x] Complex types: enum, array, map, fixed, unions and records support\n- [x] Logical Types: date, duration, time (millis and micro), datetime (millis and micro), uuid support\n- [x] Recursive Schemas\n- [x] Generate json from pydantic class instance\n\n\n\n### TODO:\n- [ ] write better tests.\n- [ ] increase test coverage from 92% to atleast 99%.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate Apache Avro schemas for Pydantic data models.",
"version": "0.4.1",
"project_urls": {
"Homepage": "https://github.com/Happy-Kunal/pydantic2avro",
"Repository": "https://github.com/Happy-Kunal/pydantic2avro"
},
"split_keywords": [
"pydantic",
" avro",
" kafka",
" messaging",
" schema",
" serialization",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6b37b95c82264b77c09afaaf05a4cd020026df6aca4eea733f5e025da4abbbf6",
"md5": "355f5f6d7b3c337a6e423d2371dc0dde",
"sha256": "10266d50f86a9daac66b4d5c7730c57b713a0291f8fe0b23511cfe650c485c8b"
},
"downloads": -1,
"filename": "pydantic2avro-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "355f5f6d7b3c337a6e423d2371dc0dde",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 7745,
"upload_time": "2024-08-18T12:06:34",
"upload_time_iso_8601": "2024-08-18T12:06:34.072986Z",
"url": "https://files.pythonhosted.org/packages/6b/37/b95c82264b77c09afaaf05a4cd020026df6aca4eea733f5e025da4abbbf6/pydantic2avro-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d68457e01a9dc1316f7389eb05e32a1d113da4891a841be5efdecf70f0decd77",
"md5": "0ada556ee62eadb98f143b70693dfabe",
"sha256": "fe719b153645e642903d5e9cf7dd9eb9c54ca951baa11d9a9b2e7e7fb4e915cb"
},
"downloads": -1,
"filename": "pydantic2avro-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "0ada556ee62eadb98f143b70693dfabe",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 5614,
"upload_time": "2024-08-18T12:06:35",
"upload_time_iso_8601": "2024-08-18T12:06:35.928779Z",
"url": "https://files.pythonhosted.org/packages/d6/84/57e01a9dc1316f7389eb05e32a1d113da4891a841be5efdecf70f0decd77/pydantic2avro-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-18 12:06:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Happy-Kunal",
"github_project": "pydantic2avro",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pydantic2avro"
}