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.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.
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
Built Distribution
File details
Details for the file jsonapi_pydantic-0.2.5.tar.gz
.
File metadata
- Download URL: jsonapi_pydantic-0.2.5.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.3 Linux/6.6.32_1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54310cabd3f65fa6bcfaaa003d173ed71aed2022e863922c66b57d93b751f4c4 |
|
MD5 | d23d926fd5b99723927b0f766ccd2696 |
|
BLAKE2b-256 | 71c85ac5af58a7b181c701cdbed9bca5d8845ea6e72e6dad0d3a74b422071a78 |
File details
Details for the file jsonapi_pydantic-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: jsonapi_pydantic-0.2.5-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.3 Linux/6.6.32_1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15100aa616b190edbb6d1a7dca2437d6023d45887c34f3f08ff40b6d0b092cea |
|
MD5 | 34256df01ffa999096965f53fa0eef65 |
|
BLAKE2b-256 | 4da9e894b27f7d07bf01518f1282060f860a90b6801d922f62cb0a053fb20656 |