[![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": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8.1",
"maintainer_email": null,
"keywords": "pydantic, avro",
"author": "Peter van 't Hof'",
"author_email": "peter.vanthof@godatadriven.com",
"download_url": "https://files.pythonhosted.org/packages/9a/dc/4c60ed4f686f0585d5bf87a72d1ab5d01bf0fd50594d5fe85f0ad7262d90/pydantic_avro-0.7.2.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\n\nclass TestModel(AvroBase):\n key1: str\n key2: int\n key2: Optional[str]\n\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.7.2",
"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": "c7d3050c325e4da6c606bffe47c9a39dcafe9ad0f96d1224cff3401fc259749e",
"md5": "6e21cd57324a090af258d77f69df42dc",
"sha256": "6cfa5311d89205624ad0e7253d1ea1eb101476ec95283ad428c4b06f8705eb29"
},
"downloads": -1,
"filename": "pydantic_avro-0.7.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6e21cd57324a090af258d77f69df42dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 11097,
"upload_time": "2024-08-09T07:48:00",
"upload_time_iso_8601": "2024-08-09T07:48:00.461372Z",
"url": "https://files.pythonhosted.org/packages/c7/d3/050c325e4da6c606bffe47c9a39dcafe9ad0f96d1224cff3401fc259749e/pydantic_avro-0.7.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9adc4c60ed4f686f0585d5bf87a72d1ab5d01bf0fd50594d5fe85f0ad7262d90",
"md5": "7bcf04c82dbce3509dd516950fd8ef5b",
"sha256": "db978958e8308ae407d430469df95c1346d5927c038b8788e1510a5aa640c03b"
},
"downloads": -1,
"filename": "pydantic_avro-0.7.2.tar.gz",
"has_sig": false,
"md5_digest": "7bcf04c82dbce3509dd516950fd8ef5b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 8719,
"upload_time": "2024-08-09T07:48:01",
"upload_time_iso_8601": "2024-08-09T07:48:01.962658Z",
"url": "https://files.pythonhosted.org/packages/9a/dc/4c60ed4f686f0585d5bf87a72d1ab5d01bf0fd50594d5fe85f0ad7262d90/pydantic_avro-0.7.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-09 07:48:01",
"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"
}