jsonapi-pydantic


Namejsonapi-pydantic JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://github.com/impocode/jsonapi-pydantic
SummaryJSON:API implementation with pydantic.
upload_time2024-04-14 14:53:54
maintainerimpocode
docs_urlNone
authorimpocode
requires_python<4.0.0,>=3.8.1
licenseMIT
keywords jsonapi pydantic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jsonapi-pydantic

<p align="center">
  <em><a href="https://jsonapi.org" target="_blank">JSON:API</a> implementation with <a href="https://pydantic-docs.helpmanual.io" target="_blank">Pydantic.</a>
  </em>
</p>
<p align="center">
  <a href="https://pypi.org/project/jsonapi-pydantic/" target="_blank">
      <img src="https://img.shields.io/pypi/v/jsonapi-pydantic" alt="PyPI">
  </a>
  <a href="https://github.com/impocode/jsonapi-pydantic/blob/master/license.md" target="_blank">
      <img src="https://img.shields.io/github/license/impocode/jsonapi-pydantic.svg" alt="License">
  </a>
</p>

## Description

`jsonapi-pydantic` provides a suite of Pydantic models matching the JSON:API specification.

## Install

```shell
$ pip install jsonapi-pydantic
```

Or use your python package manager.

## Usage

Object with primary data:

```python
from jsonapi_pydantic.v1_0 import TopLevel

external_data = {
    "data": [
        {
            "type": "articles",
            "id": "1",
            "attributes": {
                "title": "JSON:API paints my bikeshed!",
                "body": "The shortest article. Ever.",
                "created": "2015-05-22T14:56:29.000Z",
                "updated": "2015-05-22T14:56:28.000Z",
            },
            "relationships": {"author": {"data": {"id": "42", "type": "people"}}},
        }
    ],
    "included": [
        {"type": "people", "id": "42", "attributes": {"name": "John", "age": 80, "gender": "male"}}
    ],
}

top_level = TopLevel(**external_data)

print(top_level.model_dump(exclude_unset=True))
"""
{
    "data": [
        {
            "type": "articles",
            "id": "1",
            "attributes": {
                "title": "JSON:API paints my bikeshed!",
                "body": "The shortest article. Ever.",
                "created": "2015-05-22T14:56:29.000Z",
                "updated": "2015-05-22T14:56:28.000Z",
            },
            "relationships": {"author": {"data": {"id": "42", "type": "people"}}},
        }
    ],
    "included": [
        {"type": "people", "id": "42", "attributes": {"name": "John", "age": 80, "gender": "male"}}
    ],
}
"""
print(top_level.data)
"""
[
    Resource(
        type="articles",
        id="1",
        attributes={
            "title": "JSON:API paints my bikeshed!",
            "body": "The shortest article. Ever.",
            "created": "2015-05-22T14:56:29.000Z",
            "updated": "2015-05-22T14:56:28.000Z",
        },
        relationships={
            "author": Relationship(
                links=None, data=ResourceIdentifier(id="42", type="people", meta=None), meta=None
            )
        },
        links=None,
        meta=None,
    )
]
"""
```

## Examples

More examples can be found [here](https://github.com/impocode/jsonapi-pydantic/tree/master/examples).

## License

See [license.md](https://github.com/impocode/jsonapi-pydantic/blob/master/license.md).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/impocode/jsonapi-pydantic",
    "name": "jsonapi-pydantic",
    "maintainer": "impocode",
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.8.1",
    "maintainer_email": "impocode@impocode.com",
    "keywords": "jsonapi, pydantic",
    "author": "impocode",
    "author_email": "impocode@impocode.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/de/35b8ce1eda26dd99bb1325952638976310fe239f5bd726bad86d5002b996/jsonapi_pydantic-0.2.4.tar.gz",
    "platform": null,
    "description": "# jsonapi-pydantic\n\n<p align=\"center\">\n  <em><a href=\"https://jsonapi.org\" target=\"_blank\">JSON:API</a> implementation with <a href=\"https://pydantic-docs.helpmanual.io\" target=\"_blank\">Pydantic.</a>\n  </em>\n</p>\n<p align=\"center\">\n  <a href=\"https://pypi.org/project/jsonapi-pydantic/\" target=\"_blank\">\n      <img src=\"https://img.shields.io/pypi/v/jsonapi-pydantic\" alt=\"PyPI\">\n  </a>\n  <a href=\"https://github.com/impocode/jsonapi-pydantic/blob/master/license.md\" target=\"_blank\">\n      <img src=\"https://img.shields.io/github/license/impocode/jsonapi-pydantic.svg\" alt=\"License\">\n  </a>\n</p>\n\n## Description\n\n`jsonapi-pydantic` provides a suite of Pydantic models matching the JSON:API specification.\n\n## Install\n\n```shell\n$ pip install jsonapi-pydantic\n```\n\nOr use your python package manager.\n\n## Usage\n\nObject with primary data:\n\n```python\nfrom jsonapi_pydantic.v1_0 import TopLevel\n\nexternal_data = {\n    \"data\": [\n        {\n            \"type\": \"articles\",\n            \"id\": \"1\",\n            \"attributes\": {\n                \"title\": \"JSON:API paints my bikeshed!\",\n                \"body\": \"The shortest article. Ever.\",\n                \"created\": \"2015-05-22T14:56:29.000Z\",\n                \"updated\": \"2015-05-22T14:56:28.000Z\",\n            },\n            \"relationships\": {\"author\": {\"data\": {\"id\": \"42\", \"type\": \"people\"}}},\n        }\n    ],\n    \"included\": [\n        {\"type\": \"people\", \"id\": \"42\", \"attributes\": {\"name\": \"John\", \"age\": 80, \"gender\": \"male\"}}\n    ],\n}\n\ntop_level = TopLevel(**external_data)\n\nprint(top_level.model_dump(exclude_unset=True))\n\"\"\"\n{\n    \"data\": [\n        {\n            \"type\": \"articles\",\n            \"id\": \"1\",\n            \"attributes\": {\n                \"title\": \"JSON:API paints my bikeshed!\",\n                \"body\": \"The shortest article. Ever.\",\n                \"created\": \"2015-05-22T14:56:29.000Z\",\n                \"updated\": \"2015-05-22T14:56:28.000Z\",\n            },\n            \"relationships\": {\"author\": {\"data\": {\"id\": \"42\", \"type\": \"people\"}}},\n        }\n    ],\n    \"included\": [\n        {\"type\": \"people\", \"id\": \"42\", \"attributes\": {\"name\": \"John\", \"age\": 80, \"gender\": \"male\"}}\n    ],\n}\n\"\"\"\nprint(top_level.data)\n\"\"\"\n[\n    Resource(\n        type=\"articles\",\n        id=\"1\",\n        attributes={\n            \"title\": \"JSON:API paints my bikeshed!\",\n            \"body\": \"The shortest article. Ever.\",\n            \"created\": \"2015-05-22T14:56:29.000Z\",\n            \"updated\": \"2015-05-22T14:56:28.000Z\",\n        },\n        relationships={\n            \"author\": Relationship(\n                links=None, data=ResourceIdentifier(id=\"42\", type=\"people\", meta=None), meta=None\n            )\n        },\n        links=None,\n        meta=None,\n    )\n]\n\"\"\"\n```\n\n## Examples\n\nMore examples can be found [here](https://github.com/impocode/jsonapi-pydantic/tree/master/examples).\n\n## License\n\nSee [license.md](https://github.com/impocode/jsonapi-pydantic/blob/master/license.md).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "JSON:API implementation with pydantic.",
    "version": "0.2.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/impocode/jsonapi-pydantic/issues",
        "Documentation": "https://github.com/impocode/jsonapi-pydantic",
        "Homepage": "https://github.com/impocode/jsonapi-pydantic",
        "Repository": "https://github.com/impocode/jsonapi-pydantic"
    },
    "split_keywords": [
        "jsonapi",
        " pydantic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3975f66ceb250ed1cbb2429af434be35ed10e97e451e338dbb9b8f8dcc00597c",
                "md5": "5ead2c6dea67db2505c942f9c0372b75",
                "sha256": "fd59b82404b442ff62c9154f77b610f334ffcf9436b5111e65aa3a298ea10807"
            },
            "downloads": -1,
            "filename": "jsonapi_pydantic-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5ead2c6dea67db2505c942f9c0372b75",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 9273,
            "upload_time": "2024-04-14T14:53:52",
            "upload_time_iso_8601": "2024-04-14T14:53:52.368696Z",
            "url": "https://files.pythonhosted.org/packages/39/75/f66ceb250ed1cbb2429af434be35ed10e97e451e338dbb9b8f8dcc00597c/jsonapi_pydantic-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ede35b8ce1eda26dd99bb1325952638976310fe239f5bd726bad86d5002b996",
                "md5": "e280c675e5ff22755b5c1b061df4e9d4",
                "sha256": "e36455088068efb65f3213c4a1f10528501c2f66727bcbb720be2d154b7f4c94"
            },
            "downloads": -1,
            "filename": "jsonapi_pydantic-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "e280c675e5ff22755b5c1b061df4e9d4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 4872,
            "upload_time": "2024-04-14T14:53:54",
            "upload_time_iso_8601": "2024-04-14T14:53:54.219468Z",
            "url": "https://files.pythonhosted.org/packages/4e/de/35b8ce1eda26dd99bb1325952638976310fe239f5bd726bad86d5002b996/jsonapi_pydantic-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-14 14:53:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "impocode",
    "github_project": "jsonapi-pydantic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jsonapi-pydantic"
}
        
Elapsed time: 0.23466s