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.5.0.tar.gz
(21.9 kB
view details)
Built Distribution
File details
Details for the file marshmallow-jsonapi-0.5.0.tar.gz
.
File metadata
- Download URL: marshmallow-jsonapi-0.5.0.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c87bd77cf43c4d85153ab3a84cdfbb8e9d7ccc62da49a3638fbf453f98eec4de |
|
MD5 | 23b14a2deeaae5af2534aa35da1a2808 |
|
BLAKE2b-256 | 84a06bdf9070818897050ffce4c141049e2f5118f16251a7296bebc58335a899 |
Provenance
File details
Details for the file marshmallow_jsonapi-0.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: marshmallow_jsonapi-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 726a95f0a95bc20f233a85cfc406a6567926e54f3b1fa1ba039c8b532fa93a79 |
|
MD5 | 239fe4a1e29662ef882caca24aa75118 |
|
BLAKE2b-256 | 5bd2cc019020ff23337dd7cd306ebfcd7bca21c29dbc03b8fa64eddf54cc82fe |