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
marshmallow-jsonapi-0.19.0.tar.gz
(32.1 kB
view hashes)
Built Distribution
Close
Hashes for marshmallow-jsonapi-0.19.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3314aab3d88faa46661eaa4624b11d0eabc09a89e6f5feb679dd31c36b6a64b |
|
MD5 | 6b96d13bd29dd2d46d9d5c8572d106c0 |
|
BLAKE2b-256 | beda081d601b8db7d17a729faf440d99f451f521a458696685c86f92a75d5f18 |
Close
Hashes for marshmallow_jsonapi-0.19.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d541826f96ae691e68af2df21ea577e1749dbed3fd62176e4f0d064f118925d |
|
MD5 | c20000f9fc4dfc1780f561c6b40f608c |
|
BLAKE2b-256 | 056e5ebed5beb71b925751561e7161e234a8749c60e2b7f191ee3b07ada91cec |