sortedcontainers-pydantic


Namesortedcontainers-pydantic JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryPydantic support for the sortedcontainers package.
upload_time2024-03-20 17:44:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License
keywords pydantic sorted sorteddict sortedlist sortedset
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sortedcontainers-pydantic

[![PyPI](https://img.shields.io/pypi/v/sortedcontainers-pydantic.svg)](https://pypi.org/project/sortedcontainers-pydantic/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/sortedcontainers-pydantic)](https://pypi.org/project/sortedcontainers-pydantic/)
[![tests](https://github.com/drivendataorg/sortedcontainers-pydantic/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/drivendataorg/sortedcontainers-pydantic/actions/workflows/tests.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/drivendataorg/sortedcontainers-pydantic/branch/main/graph/badge.svg)](https://codecov.io/gh/drivendataorg/sortedcontainers-pydantic)

This package adds [Pydantic](https://docs.pydantic.dev/latest/) support to [sortedcontainers](https://github.com/grantjenks/python-sortedcontainers/), a fast pure-Python library for sorted mutable collections. 

It implements [Pydantic's special methods](https://docs.pydantic.dev/latest/concepts/types/#customizing-validation-with-__get_pydantic_core_schema__) on subclasses of sortedcontainer's `SortedDict`, `SortedList`, and `SortedSet` classes so that you can use them with Pydantic's models, validation, and serialization. To use, simply import the respective class of the same name from `sortedcontainers_pydantic` instead of from `sortedcontainers`. Only Pydantic V2 is supported.

```python
from pydantic import BaseModel, TypeAdapter
from sortedcontainers_pydantic import SortedList

class MyModel(BaseModel):
    sorted_list: SortedList[int]

MyModel(sorted_list=[3, 1, 2])
#> MyModel(sorted_list=SortedList([1, 2, 3]))

MyModel.model_validate_json('{"sorted_list": [3, 1, 2]}')
#> MyModel(sorted_list=SortedList([1, 2, 3]))

MyModel(sorted_list=[3, 1, 2]).model_dump_json()
#> '{"sorted_list":[1,2,3]}'

TypeAdapter(SortedList).validate_python([3, 1, 2])
#> SortedList([1, 2, 3])

TypeAdapter(SortedList).validate_json("[3, 1, 2]")
#> SortedList([1, 2, 3])
```

<sup>Reproducible example created by [reprexlite](https://github.com/jayqi/reprexlite) v0.5.0</sup>

## Installation

sortedcontainers-pydantic is available on [PyPI](https://pypi.org/project/sortedcontainers-pydantic/). You can install it with 

```bash
pip install sortedcontainers-pydantic
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sortedcontainers-pydantic",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pydantic, sorted, sorteddict, sortedlist, sortedset",
    "author": null,
    "author_email": "DrivenData <info@drivendata.org>, Jay Qi <jayqi.opensource@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/25/39/b8dbaf922f4f0fd1d7d033f12fe22b5c8b14a41eac6caab671e9cb59144b/sortedcontainers_pydantic-1.0.0.tar.gz",
    "platform": null,
    "description": "# sortedcontainers-pydantic\n\n[![PyPI](https://img.shields.io/pypi/v/sortedcontainers-pydantic.svg)](https://pypi.org/project/sortedcontainers-pydantic/)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/sortedcontainers-pydantic)](https://pypi.org/project/sortedcontainers-pydantic/)\n[![tests](https://github.com/drivendataorg/sortedcontainers-pydantic/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/drivendataorg/sortedcontainers-pydantic/actions/workflows/tests.yml?query=branch%3Amain)\n[![codecov](https://codecov.io/gh/drivendataorg/sortedcontainers-pydantic/branch/main/graph/badge.svg)](https://codecov.io/gh/drivendataorg/sortedcontainers-pydantic)\n\nThis package adds [Pydantic](https://docs.pydantic.dev/latest/) support to [sortedcontainers](https://github.com/grantjenks/python-sortedcontainers/), a fast pure-Python library for sorted mutable collections. \n\nIt implements [Pydantic's special methods](https://docs.pydantic.dev/latest/concepts/types/#customizing-validation-with-__get_pydantic_core_schema__) on subclasses of sortedcontainer's `SortedDict`, `SortedList`, and `SortedSet` classes so that you can use them with Pydantic's models, validation, and serialization. To use, simply import the respective class of the same name from `sortedcontainers_pydantic` instead of from `sortedcontainers`. Only Pydantic V2 is supported.\n\n```python\nfrom pydantic import BaseModel, TypeAdapter\nfrom sortedcontainers_pydantic import SortedList\n\nclass MyModel(BaseModel):\n    sorted_list: SortedList[int]\n\nMyModel(sorted_list=[3, 1, 2])\n#> MyModel(sorted_list=SortedList([1, 2, 3]))\n\nMyModel.model_validate_json('{\"sorted_list\": [3, 1, 2]}')\n#> MyModel(sorted_list=SortedList([1, 2, 3]))\n\nMyModel(sorted_list=[3, 1, 2]).model_dump_json()\n#> '{\"sorted_list\":[1,2,3]}'\n\nTypeAdapter(SortedList).validate_python([3, 1, 2])\n#> SortedList([1, 2, 3])\n\nTypeAdapter(SortedList).validate_json(\"[3, 1, 2]\")\n#> SortedList([1, 2, 3])\n```\n\n<sup>Reproducible example created by [reprexlite](https://github.com/jayqi/reprexlite) v0.5.0</sup>\n\n## Installation\n\nsortedcontainers-pydantic is available on [PyPI](https://pypi.org/project/sortedcontainers-pydantic/). You can install it with \n\n```bash\npip install sortedcontainers-pydantic\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Pydantic support for the sortedcontainers package.",
    "version": "1.0.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/jayqi/sortedcontainers-pydantic/issues",
        "Homepage": "https://github.com/jayqi/sortedcontainers-pydantic/",
        "Repository": "https://github.com/jayqi/sortedcontainers-pydantic"
    },
    "split_keywords": [
        "pydantic",
        " sorted",
        " sorteddict",
        " sortedlist",
        " sortedset"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6df44d01fd09a88a6d9707b4609568415cb21585e83f42282dd848c9bc0af95c",
                "md5": "6a8bccbd1504e030b7bdf193be18ab29",
                "sha256": "07e92e9b85dbf9248e0a5b59e0311a095e6fb27e0dc461b1209ead5a550b60b2"
            },
            "downloads": -1,
            "filename": "sortedcontainers_pydantic-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a8bccbd1504e030b7bdf193be18ab29",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4619,
            "upload_time": "2024-03-20T17:44:45",
            "upload_time_iso_8601": "2024-03-20T17:44:45.764900Z",
            "url": "https://files.pythonhosted.org/packages/6d/f4/4d01fd09a88a6d9707b4609568415cb21585e83f42282dd848c9bc0af95c/sortedcontainers_pydantic-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2539b8dbaf922f4f0fd1d7d033f12fe22b5c8b14a41eac6caab671e9cb59144b",
                "md5": "46d58a0027bcbac1ed9c1a2459edbd08",
                "sha256": "eb0e4aeb5197d690165f0a7b1a55c490eabe4b21375c3a91726373b2551e25ee"
            },
            "downloads": -1,
            "filename": "sortedcontainers_pydantic-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "46d58a0027bcbac1ed9c1a2459edbd08",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8191,
            "upload_time": "2024-03-20T17:44:47",
            "upload_time_iso_8601": "2024-03-20T17:44:47.558089Z",
            "url": "https://files.pythonhosted.org/packages/25/39/b8dbaf922f4f0fd1d7d033f12fe22b5c8b14a41eac6caab671e9cb59144b/sortedcontainers_pydantic-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-20 17:44:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jayqi",
    "github_project": "sortedcontainers-pydantic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sortedcontainers-pydantic"
}
        
Elapsed time: 0.21780s