extendable-pydantic


Nameextendable-pydantic JSON
Version 1.2.1 PyPI version JSON
download
home_page
Summary
upload_time2023-11-13 17:46:50
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2021 Laurent Mignon (ACSONE) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![CI](https://github.com/lmignon/pydantic-ext/actions/workflows/ci.yml/badge.svg)](https://github.com/lmignon/pydantic-ext/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/lmignon/pydantic-ext/branch/master/graph/badge.svg?token=Z9FWM57T14)](https://codecov.io/gh/lmignon/pydantic-ext)

# Extendable Pydantic

This addons provides a new type used to declare [Pydantic](https://pypi.org/project/pydantic/)
model as [Extendable](https://pypi.org/project/extendable/) class.

From release 1.0.0 it only supports Pydantic >= 2.0.0.


```python
from pydantic import BaseModel
from extendable_pydantic import ExtendableModelMeta
from extendable import context, registry

class Location(BaseModel, metaclass=ExtendableModelMeta):
    lat = 0.1
    lng = 10.1

class ExtendedLocation(Location, extends=Location):
    name: str

_registry = registry.ExtendableClassesRegistry()
context.extendable_registry.set(_registry)
_registry.init_registry()

loc = Location(**{"lat": 12.3, "lng": 13.2, "name": "My Loc"})

loc.model_dump() == {"lat": 12.3, "lng": 13.2, "name": "My Loc"}
#> True

loc.model_json_schema()
#> {'title': 'Location', 'type': 'object', 'properties': {'lat': {'title': 'Lat', 'default': 0.1, 'type': 'number'}, 'lng': {'title': 'Lng', 'default': 10.1, 'type': 'number'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['name']}
```

## Development

`pip install -e .`

Then, copy `extendable_pydantic_patcher.pth` to `$VIRTUAL_ENV/lib/python3.10/site-packages`.

## Release


* run ``bumpversion patch|minor|major --list
* Check the new_version value returned by the previous command
* run towncrier build.
* Inspect and commit the updated HISTORY.rst.
* git tag {new_version} ; git push --tags.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "extendable-pydantic",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Laurent Mignon <laurent.mignon@acsone.eu>",
    "download_url": "https://files.pythonhosted.org/packages/78/e2/c1d23859527149b39b55a6dcd149c5d9eb07e9fd452cad91e0cc64822a79/extendable_pydantic-1.2.1.tar.gz",
    "platform": null,
    "description": "[![CI](https://github.com/lmignon/pydantic-ext/actions/workflows/ci.yml/badge.svg)](https://github.com/lmignon/pydantic-ext/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/lmignon/pydantic-ext/branch/master/graph/badge.svg?token=Z9FWM57T14)](https://codecov.io/gh/lmignon/pydantic-ext)\n\n# Extendable Pydantic\n\nThis addons provides a new type used to declare [Pydantic](https://pypi.org/project/pydantic/)\nmodel as [Extendable](https://pypi.org/project/extendable/) class.\n\nFrom release 1.0.0 it only supports Pydantic >= 2.0.0.\n\n\n```python\nfrom pydantic import BaseModel\nfrom extendable_pydantic import ExtendableModelMeta\nfrom extendable import context, registry\n\nclass Location(BaseModel, metaclass=ExtendableModelMeta):\n    lat = 0.1\n    lng = 10.1\n\nclass ExtendedLocation(Location, extends=Location):\n    name: str\n\n_registry = registry.ExtendableClassesRegistry()\ncontext.extendable_registry.set(_registry)\n_registry.init_registry()\n\nloc = Location(**{\"lat\": 12.3, \"lng\": 13.2, \"name\": \"My Loc\"})\n\nloc.model_dump() == {\"lat\": 12.3, \"lng\": 13.2, \"name\": \"My Loc\"}\n#> True\n\nloc.model_json_schema()\n#> {'title': 'Location', 'type': 'object', 'properties': {'lat': {'title': 'Lat', 'default': 0.1, 'type': 'number'}, 'lng': {'title': 'Lng', 'default': 10.1, 'type': 'number'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['name']}\n```\n\n## Development\n\n`pip install -e .`\n\nThen, copy `extendable_pydantic_patcher.pth` to `$VIRTUAL_ENV/lib/python3.10/site-packages`.\n\n## Release\n\n\n* run ``bumpversion patch|minor|major --list\n* Check the new_version value returned by the previous command\n* run towncrier build.\n* Inspect and commit the updated HISTORY.rst.\n* git tag {new_version} ; git push --tags.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2021 Laurent Mignon (ACSONE)  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "",
    "version": "1.2.1",
    "project_urls": {
        "Source": "https://github.com/lmignon/extendable-pydantic"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49acc617e99da97cd4d1ecb080d14afb3616458bd397e94d8045790658dee16c",
                "md5": "446a3b1043859dc1532db267f1fef396",
                "sha256": "911da0d6843a1b09ba0f3f5437873f301142c290cbda967ac3cd29f040f143a1"
            },
            "downloads": -1,
            "filename": "extendable_pydantic-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "446a3b1043859dc1532db267f1fef396",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10042,
            "upload_time": "2023-11-13T17:46:49",
            "upload_time_iso_8601": "2023-11-13T17:46:49.651920Z",
            "url": "https://files.pythonhosted.org/packages/49/ac/c617e99da97cd4d1ecb080d14afb3616458bd397e94d8045790658dee16c/extendable_pydantic-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78e2c1d23859527149b39b55a6dcd149c5d9eb07e9fd452cad91e0cc64822a79",
                "md5": "92fe47b2275c8ea8109de0b09e8d3882",
                "sha256": "3b5cfaeaff86eb24009503bba0651cc9a23c89fe42139a23f400607d47696942"
            },
            "downloads": -1,
            "filename": "extendable_pydantic-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "92fe47b2275c8ea8109de0b09e8d3882",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8297,
            "upload_time": "2023-11-13T17:46:50",
            "upload_time_iso_8601": "2023-11-13T17:46:50.989694Z",
            "url": "https://files.pythonhosted.org/packages/78/e2/c1d23859527149b39b55a6dcd149c5d9eb07e9fd452cad91e0cc64822a79/extendable_pydantic-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-13 17:46:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lmignon",
    "github_project": "extendable-pydantic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "extendable-pydantic"
}
        
Elapsed time: 0.16346s