JSON:API implementation with pydantic.
Project description
jsonapi-pydantic
JSON:API implementation with Pydantic.
Description
jsonapi-pydantic
provides a suite of Pydantic models matching the JSON:API specification.
Install
$ pip install jsonapi-pydantic
Or use your python package manager.
Usage
Object with primary data:
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonapi_pydantic-0.2.0.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for jsonapi_pydantic-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c80e1e1cfa1d1f8a6d635f06288c6974743e5dfd7ad570db5bffac155f29ad3 |
|
MD5 | 38914db2baac335932e7ced1fde8b7be |
|
BLAKE2b-256 | b4f6063e91bb5ca791d34af86d15ab4ad6bebfcb4e5448ea7cd4086bc59eaa28 |