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.7.0.tar.gz
(22.7 kB
view details)
Built Distribution
File details
Details for the file marshmallow-jsonapi-0.7.0.tar.gz
.
File metadata
- Download URL: marshmallow-jsonapi-0.7.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04d5a1999d1f10b3398cea6d34554135eeb701a10a0019b15758cac9fb6e59b2 |
|
MD5 | 64269a52a6e6627c98266d16ace13b63 |
|
BLAKE2b-256 | f4c1241f5d20d7a7031c25fe581e23fa5e974e238565544353a320448158bf64 |
Provenance
File details
Details for the file marshmallow_jsonapi-0.7.0-py2.py3-none-any.whl
.
File metadata
- Download URL: marshmallow_jsonapi-0.7.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d7a9b12abcbc7af396b31bb0b245c8e6635708e9ebf6aeeb346ef9d7dd8942f |
|
MD5 | ee837efa663a7db9aa564716b3040cd0 |
|
BLAKE2b-256 | b108f92a3e26aa0f9fcdf306cfe2489b06203a9367a5d5ce9be5bf345aff4a00 |