an implementation of JSON:api using pydantic
Project description
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)
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
Close
Hashes for pydantic_jsonapi-0.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c034c01d21051bc8f8b8968b64dbc897bac43e84f45a6e2c5a1db61276c2408a |
|
MD5 | 6c3fa81e8e07fa371cd18c071cc069de |
|
BLAKE2b-256 | fdba04fbf53245705a4a06638fb5a39a1068d993669c55a107e7ff630990833a |