# 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.one",
"keywords": "jsonapi, pydantic",
"author": "impocode",
"author_email": "impocode@impocode.one",
"download_url": "https://files.pythonhosted.org/packages/71/c8/5ac5af58a7b181c701cdbed9bca5d8845ea6e72e6dad0d3a74b422071a78/jsonapi_pydantic-0.2.5.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.5",
"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": "4da9e894b27f7d07bf01518f1282060f860a90b6801d922f62cb0a053fb20656",
"md5": "34256df01ffa999096965f53fa0eef65",
"sha256": "15100aa616b190edbb6d1a7dca2437d6023d45887c34f3f08ff40b6d0b092cea"
},
"downloads": -1,
"filename": "jsonapi_pydantic-0.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "34256df01ffa999096965f53fa0eef65",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.8.1",
"size": 9296,
"upload_time": "2024-06-14T07:53:44",
"upload_time_iso_8601": "2024-06-14T07:53:44.823547Z",
"url": "https://files.pythonhosted.org/packages/4d/a9/e894b27f7d07bf01518f1282060f860a90b6801d922f62cb0a053fb20656/jsonapi_pydantic-0.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "71c85ac5af58a7b181c701cdbed9bca5d8845ea6e72e6dad0d3a74b422071a78",
"md5": "d23d926fd5b99723927b0f766ccd2696",
"sha256": "54310cabd3f65fa6bcfaaa003d173ed71aed2022e863922c66b57d93b751f4c4"
},
"downloads": -1,
"filename": "jsonapi_pydantic-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "d23d926fd5b99723927b0f766ccd2696",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.8.1",
"size": 4944,
"upload_time": "2024-06-14T07:53:46",
"upload_time_iso_8601": "2024-06-14T07:53:46.477084Z",
"url": "https://files.pythonhosted.org/packages/71/c8/5ac5af58a7b181c701cdbed9bca5d8845ea6e72e6dad0d3a74b422071a78/jsonapi_pydantic-0.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-14 07:53:46",
"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"
}