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.6.0.tar.gz
(22.5 kB
view hashes)
Built Distribution
Close
Hashes for marshmallow-jsonapi-0.6.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f6d1c52691b59cf4b4ee47ea54edee12245879fe54cd5029bdd7ec4fb7d9167 |
|
MD5 | 220b6154f9a708bb4bfe4d46d2840d97 |
|
BLAKE2b-256 | 8c99415d160f24f3eec725eaed5ee3ff13aa0419e17d30c7196e2ca4c5027763 |
Close
Hashes for marshmallow_jsonapi-0.6.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5202cafbb00681e0efd6a342a8f93adbf44b9d109397ecae2e4dcb06e4ac236 |
|
MD5 | 758fa2a072f78b96fcebf30ecc25958e |
|
BLAKE2b-256 | 2b5873aae6765b731fde02d830c1eb4991a73314d68c07d13653464bf9ff6366 |