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"
post_schema = PostSchema()
post_schema.dump(post)
# {
# "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 >= 3.6
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.23.1.tar.gz
(35.3 kB
view hashes)
Built Distribution
Close
Hashes for marshmallow-jsonapi-0.23.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d5567ad98d834149e4329d244732bda0185dc51b5fef0ec7dc58e9d1d7c0493 |
|
MD5 | b580e546d62ead38246ba8ce1f8a7a98 |
|
BLAKE2b-256 | 2b18d0544c770e9e83709a2af504fe6becf0c9c5bca5974fbb0e9db93b0735c7 |
Close
Hashes for marshmallow_jsonapi-0.23.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 289ac50cc65d9febfe432892345f44b99d4520d48538a86cf274549712fa6a82 |
|
MD5 | adaa5ad9a41535b0ecf9c17c2e441df6 |
|
BLAKE2b-256 | d03bdf51423e25652ea161a3ab77cd85bdcfc96c3ca77646a56a305a556adda7 |