JSON API 1.0 (https://jsonapi.org) formatting with marshmallow
Project description
Homepage: http://marshmallow-jsonapi.readthedocs.io/
JSON API 1.0 (https://jsonapi.org) formatting with marshmallow.
marshmallow-jsonapi provides a simple way to produce JSON API-compliant data in any Python web framework.
from marshmallow_jsonapi import Schema, fields
class PostSchema(Schema):
id = fields.Str(dump_only=True)
title = fields.Str()
author = fields.Relationship(
'/authors/{author_id}',
related_url_kwargs={'author_id': '<author.id>'},
)
comments = fields.Relationship(
'/posts/{post_id}/comments',
related_url_kwargs={'post_id': '<id>'},
# Include resource linkage
many=True, include_resource_linkage=True,
type_='comments'
)
class Meta:
type_ = 'posts'
strict = True
post_schema = PostSchema()
post_schema.dump(post).data
# {
# "data": {
# "id": "1",
# "type": "posts"
# "attributes": {
# "title": "JSON API paints my bikeshed!"
# },
# "relationships": {
# "author": {
# "links": {
# "related": "/authors/9"
# }
# },
# "comments": {
# "links": {
# "related": "/posts/1/comments/"
# }
# "data": [
# {"id": 5, "type": "comments"},
# {"id": 12, "type": "comments"}
# ],
# }
# },
# }
# }
Installation
pip install marshmallow-jsonapi
Documentation
Full documentation is available at https://marshmallow-jsonapi.readthedocs.io/.
Requirements
Python >= 2.7 or >= 3.5
Project Links
License
MIT licensed. See the bundled LICENSE file for more details.
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 marshmallow-jsonapi-0.19.0.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | da63254b23020b26388ec474aca6107fc11e16c67f39efc049d84a777347a73c |
|
MD5 | 56b89d910fe5bb4ce8b0304e754ab988 |
|
BLAKE2b-256 | 3981d1a2d2c410d0f64170996b22172a6e955977e3bba32e2ecdaede02b8a1bc |
Close
Hashes for marshmallow_jsonapi-0.19.0.post0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f2838b245e4b8b132dd90dc51e9ab64f24fcec33503917cd3cc698cc33d57d3 |
|
MD5 | 07dc22c4b7685d1ee4eda83a53ddfe2e |
|
BLAKE2b-256 | 6bf60f0b888476ed4aa5cb5ce9a1e9d4e84b68613daf15e56eb4a32c4245beae |