Metadata-Version: 2.1
Name: jsonapi-pydantic
Version: 0.1.1
Summary: JSON:API implementation with pydantic.
Home-page: https://github.com/impocode/jsonapi-pydantic
License: MIT
Keywords: jsonapi,pydantic
Author: impocode
Author-email: impocode@impocode.com
Maintainer: impocode
Maintainer-email: impocode@impocode.com
Requires-Python: >=3.7,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Typing :: Typed
Requires-Dist: pydantic (>=1.10.2,<2.0.0)
Project-URL: Bug Tracker, https://github.com/impocode/jsonapi-pydantic/issues
Project-URL: Documentation, https://github.com/impocode/jsonapi-pydantic
Project-URL: Repository, https://github.com/impocode/jsonapi-pydantic
Description-Content-Type: text/markdown

# 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.dict(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,
    )
]
"""
```

## License

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

