JSON API 1.0 (https://jsonapi.org) formatting with marshmallow
Project description
Homepage: http://marshmallow-jsonapi.rtfd.org/
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_data=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.org/.
Requirements
Python >= 2.7 or >= 3.3
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
marshmallow-jsonapi-0.3.0.tar.gz
(17.9 kB
view hashes)
Built Distribution
Close
Hashes for marshmallow-jsonapi-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef85ad2fb3a13d563b9794d74028965443ff5d0aad8fa038a5f7c49958927627 |
|
MD5 | eec8d14b201130cdae6615f16df8d376 |
|
BLAKE2b-256 | f4f7c14e03a9ac7ae65810a04bb2962113c19fdb0db3573fa464c7f288cd769c |
Close
Hashes for marshmallow_jsonapi-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbe4a9ed3c6fcec3261a1fc896e89c459ec42bbcef69f9eeb6f0a144419bfa5c |
|
MD5 | 7e9a61b7e53bfabb4d04643f34d2b561 |
|
BLAKE2b-256 | 4cfc5566e169b961f59f8355f5ec012cfecc515465011e7ca7596c3bb2beb44a |