pydantic-jsonapi
an implementation of JSON:api using pydantic for validation
from pydantic_jsonapi import JsonApiModel
from pydantic import BaseModel
class Item(BaseModel):
name: str
quantity: int
price: float
ItemRequest, ItemResponse = JsonApiModel('item', Item)
# request validation
request = {
'data': {
'type': 'item',
'attributes': {
'name': 'apple',
'quantity': 10,
'price': 1.20,
},
}
}
ItemRequest(**request)
#response validation
response = {
'data': {
'id': 'abc123',
'type': 'item',
'attributes': {
'name': 'apple',
'quantity': 10,
'price': 1.20,
},
'relationships': {
'store': {
'links': {
'related': '/stores/123'
}
}
}
},
'links': {
'self': '/item/abc123'
}
}
ItemResponse(**response)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pydantic_jsonapi-0.11.0.tar.gz.
File metadata
- Download URL: pydantic_jsonapi-0.11.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0c72d7543017121e49a41ee7e36224ba1cc3627be5efac048e3b81425e623a8
|
|
| MD5 |
a0c513ad5be44551c2e430ea25163976
|
|
| BLAKE2b-256 |
0c08688ff0a722796c7671576cc6c1936f64302f5d20356631947dcd7b88b141
|