pydantic2avro


Namepydantic2avro JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/Happy-Kunal/pydantic2avro
SummaryGenerate Apache Avro schemas for Pydantic data models.
upload_time2024-03-04 18:43:35
maintainer
docs_urlNone
authorKunal Sharma
requires_python>=3.12,<4.0
licenseMIT
keywords pydantic avro kafka messaging schema serialization python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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": "",
    "docs_url": null,
    "requires_python": ">=3.12,<4.0",
    "maintainer_email": "",
    "keywords": "pydantic,avro,kafka,messaging,schema,serialization,python",
    "author": "Kunal Sharma",
    "author_email": "happykunal@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/c8/c0/1fad7d576382fae88b010ee7e63f4a6747714dc3f011865585fbae22e713/pydantic2avro-0.2.0.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.2.0",
    "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": "3774c214f68cce7350cd778b344a0220b5f6a4cd7e7d7eb4c10546f187340609",
                "md5": "a0600a5c1b497b04df12520c54ebf114",
                "sha256": "63037666ed6a293cf2c56cee8e6680ac6ec1179add190592005da19f7fd97965"
            },
            "downloads": -1,
            "filename": "pydantic2avro-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a0600a5c1b497b04df12520c54ebf114",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12,<4.0",
            "size": 7596,
            "upload_time": "2024-03-04T18:43:34",
            "upload_time_iso_8601": "2024-03-04T18:43:34.101499Z",
            "url": "https://files.pythonhosted.org/packages/37/74/c214f68cce7350cd778b344a0220b5f6a4cd7e7d7eb4c10546f187340609/pydantic2avro-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8c01fad7d576382fae88b010ee7e63f4a6747714dc3f011865585fbae22e713",
                "md5": "5027b98b2c811b84d06105832b70be5e",
                "sha256": "167f31de1a5835982b1f0d1debc9d96782d69813908519371c9eb7abfe1b51f0"
            },
            "downloads": -1,
            "filename": "pydantic2avro-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5027b98b2c811b84d06105832b70be5e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12,<4.0",
            "size": 5454,
            "upload_time": "2024-03-04T18:43:35",
            "upload_time_iso_8601": "2024-03-04T18:43:35.944585Z",
            "url": "https://files.pythonhosted.org/packages/c8/c0/1fad7d576382fae88b010ee7e63f4a6747714dc3f011865585fbae22e713/pydantic2avro-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-04 18:43: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"
}
        
Elapsed time: 0.19911s