[![Python package](https://github.com/godatadriven/pydantic-avro/actions/workflows/python-package.yml/badge.svg)](https://github.com/godatadriven/pydantic-avro/actions/workflows/python-package.yml)
[![codecov](https://codecov.io/gh/godatadriven/pydantic-avro/branch/main/graph/badge.svg?token=5L08GOERAW)](https://codecov.io/gh/godatadriven/pydantic-avro)
[![PyPI version](https://badge.fury.io/py/pydantic-avro.svg)](https://badge.fury.io/py/pydantic-avro)
[![CodeQL](https://github.com/godatadriven/pydantic-avro/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/godatadriven/pydantic-avro/actions/workflows/codeql-analysis.yml)
# pydantic-avro
This library can convert a pydantic class to a avro schema or generate python code from a avro schema.
### Install
```bash
pip install pydantic-avro
```
### Pydantic class to avro schema
```python
import json
from typing import Optional
from pydantic_avro.base import AvroBase
class TestModel(AvroBase):
key1: str
key2: int
key2: Optional[str]
schema_dict: dict = TestModel.avro_schema()
print(json.dumps(schema_dict))
```
### Avro schema to pydantic
```shell
# Print to stdout
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc
# Save it to a file
pydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py
```
### Install for developers
###### Install package
- Requirement: Poetry 1.*
```shell
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
```
##### Run linting
The linting is checked in the github workflow. To fix and review issues run this:
```shell
black . # Auto fix all issues
isort . # Auto fix all issues
pflake . # Only display issues, fixing is manual
```
Raw data
{
"_id": null,
"home_page": "https://github.com/godatadriven/pydantic-avro",
"name": "pydantic-avro",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "pydantic,avro",
"author": "Peter van 't Hof'",
"author_email": "peter.vanthof@godatadriven.com",
"download_url": "https://files.pythonhosted.org/packages/39/45/b9daef8b134fb617b14f0b73b5d741983d286eea756d1646a04e38a61c96/pydantic_avro-0.6.5.tar.gz",
"platform": null,
"description": "[![Python package](https://github.com/godatadriven/pydantic-avro/actions/workflows/python-package.yml/badge.svg)](https://github.com/godatadriven/pydantic-avro/actions/workflows/python-package.yml)\n[![codecov](https://codecov.io/gh/godatadriven/pydantic-avro/branch/main/graph/badge.svg?token=5L08GOERAW)](https://codecov.io/gh/godatadriven/pydantic-avro)\n[![PyPI version](https://badge.fury.io/py/pydantic-avro.svg)](https://badge.fury.io/py/pydantic-avro)\n[![CodeQL](https://github.com/godatadriven/pydantic-avro/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/godatadriven/pydantic-avro/actions/workflows/codeql-analysis.yml)\n\n# pydantic-avro\n\nThis library can convert a pydantic class to a avro schema or generate python code from a avro schema.\n\n### Install\n\n```bash\npip install pydantic-avro\n```\n\n### Pydantic class to avro schema\n\n```python\nimport json\nfrom typing import Optional\n\nfrom pydantic_avro.base import AvroBase\n\nclass TestModel(AvroBase):\n key1: str\n key2: int\n key2: Optional[str]\n\nschema_dict: dict = TestModel.avro_schema()\nprint(json.dumps(schema_dict))\n\n```\n\n### Avro schema to pydantic\n\n```shell\n# Print to stdout\npydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc\n\n# Save it to a file\npydantic-avro avro_to_pydantic --asvc /path/to/schema.asvc --output /path/to/output.py\n```\n\n\n### Install for developers\n\n###### Install package\n\n- Requirement: Poetry 1.*\n\n```shell\npoetry install\n```\n\n###### Run unit tests\n```shell\npytest\ncoverage run -m pytest # with coverage\n# or (depends on your local env) \npoetry run pytest\npoetry run coverage run -m pytest # with coverage\n```\n\n##### Run linting\n\nThe linting is checked in the github workflow. To fix and review issues run this:\n```shell\nblack . # Auto fix all issues\nisort . # Auto fix all issues\npflake . # Only display issues, fixing is manual\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Converting pydantic classes to avro schemas",
"version": "0.6.5",
"project_urls": {
"Homepage": "https://github.com/godatadriven/pydantic-avro",
"Repository": "https://github.com/godatadriven/pydantic-avro"
},
"split_keywords": [
"pydantic",
"avro"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9989900e91f34fe10b39f9bd73c4e8195267258d08ea8d44eb5d9e7792171bb1",
"md5": "27c18f0e3cd223e1f5f956b2f12327a1",
"sha256": "4b9f50614e666a88560caf4d60951256962ec22255697f2147484ed408238a9d"
},
"downloads": -1,
"filename": "pydantic_avro-0.6.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "27c18f0e3cd223e1f5f956b2f12327a1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 8000,
"upload_time": "2023-08-09T07:36:21",
"upload_time_iso_8601": "2023-08-09T07:36:21.893929Z",
"url": "https://files.pythonhosted.org/packages/99/89/900e91f34fe10b39f9bd73c4e8195267258d08ea8d44eb5d9e7792171bb1/pydantic_avro-0.6.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3945b9daef8b134fb617b14f0b73b5d741983d286eea756d1646a04e38a61c96",
"md5": "08cc3fead4f370ddfb8c93cfd6cd436d",
"sha256": "f1897018dafb010a859df037637339dddd82fdfca3696ebd7a0837accac036a3"
},
"downloads": -1,
"filename": "pydantic_avro-0.6.5.tar.gz",
"has_sig": false,
"md5_digest": "08cc3fead4f370ddfb8c93cfd6cd436d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 6582,
"upload_time": "2023-08-09T07:36:22",
"upload_time_iso_8601": "2023-08-09T07:36:22.947619Z",
"url": "https://files.pythonhosted.org/packages/39/45/b9daef8b134fb617b14f0b73b5d741983d286eea756d1646a04e38a61c96/pydantic_avro-0.6.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-09 07:36:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "godatadriven",
"github_project": "pydantic-avro",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic-avro"
}