Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DeanWay/pydantic-jsonapi
an implementation of JSON:api using pydantic for validation
https://github.com/DeanWay/pydantic-jsonapi
Last synced: 13 days ago
JSON representation
an implementation of JSON:api using pydantic for validation
- Host: GitHub
- URL: https://github.com/DeanWay/pydantic-jsonapi
- Owner: DeanWay
- License: mit
- Created: 2019-09-12T15:26:13.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-13T20:39:50.000Z (over 3 years ago)
- Last Synced: 2024-10-01T20:06:56.954Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 76.2 KB
- Stars: 69
- Watchers: 8
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pydantic-jsonapi
[![Build Status](https://travis-ci.org/DeanWay/pydantic-jsonapi.svg?branch=master)](https://travis-ci.org/DeanWay/pydantic-jsonapi)
[![PyPi Link](https://img.shields.io/pypi/pyversions/pydantic-jsonapi.svg)](https://pypi.org/project/pydantic-jsonapi/)an implementation of JSON:api using pydantic for validation
```python
from pydantic_jsonapi import JsonApiModel
from pydantic import BaseModelclass Item(BaseModel):
name: str
quantity: int
price: floatItemRequest, 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)
```