Skip to main content

JSON API 1.0 (https://jsonapi.org) formatting with marshmallow

Project description

⚠️ I still need this package in some of my projects. This for is minimal work required to keep it working

  • with newer Pythons and tooling (uv)

  • new marshmallow v4.x

⚠️ To allow integrating it in my projects, it is published on PyPI as marshmallow-jsonapi-minfork.

PyPI version Documentation code style: black

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

License

MIT licensed. See the bundled LICENSE file for more details.

Project details


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_minfork-0.26.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marshmallow_jsonapi_minfork-0.26.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file marshmallow_jsonapi_minfork-0.26.0.tar.gz.

File metadata

File hashes

Hashes for marshmallow_jsonapi_minfork-0.26.0.tar.gz
Algorithm Hash digest
SHA256 e56fc3978ae1c855dd3f47b2879a58662255b38e55b11f10ea8cadb8879fb60b
MD5 c3a39813d578d8863dc8e14cc4964b43
BLAKE2b-256 22901b998dd32424acee0338cda059a96c0ab1a9559017ddad55702ef1965fdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for marshmallow_jsonapi_minfork-0.26.0.tar.gz:

Publisher: pypi-publish.yaml on tadams42/marshmallow-jsonapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file marshmallow_jsonapi_minfork-0.26.0-py3-none-any.whl.

File metadata

File hashes

Hashes for marshmallow_jsonapi_minfork-0.26.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74c87b44d66bdca4dfee9608915dd53c8a59e3e179adf89a0afbf200938442bd
MD5 e9b2b7e8aba4c5b456146c07129ea45d
BLAKE2b-256 68658a78480c052bac6dca9c87e46daf4515bb0c4dcc5136f46b4789dcb6fb7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for marshmallow_jsonapi_minfork-0.26.0-py3-none-any.whl:

Publisher: pypi-publish.yaml on tadams42/marshmallow-jsonapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page