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). For the time being, I have no resources to invest into any major work on this. Therefore, it will not be upgraded to marshmallow 4 in foreseeable future.

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

PyPI version Build status Documentation marshmallow 3 compatible 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.25.0.tar.gz (36.0 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.25.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for marshmallow_jsonapi_minfork-0.25.0.tar.gz
Algorithm Hash digest
SHA256 cb9b526971b289c7f6da76071c56bc9c5efaf224f5b4aafe7c798c91b9205bc6
MD5 397f7bde51749e51941180643d0be832
BLAKE2b-256 67d1c95449d51aee04c18b180c2025ceafaeaf8ec14df3fb7d235d5386c3f59c

See more details on using hashes here.

Provenance

The following attestation bundles were made for marshmallow_jsonapi_minfork-0.25.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.25.0-py3-none-any.whl.

File metadata

File hashes

Hashes for marshmallow_jsonapi_minfork-0.25.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0cfd18429f2f77cae0122873de5645a8f635eb2408a5e72c250057821682863
MD5 a39783e520ea7c22801424a4335a0135
BLAKE2b-256 d7e382e28cb9c28512123369166a65684a08b6f94f75c34b8fdd1505a365bcd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for marshmallow_jsonapi_minfork-0.25.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