Skip to content

Arkelis/jsonapy

Repository files navigation

JSON:APy - Loading and Dumping JSON:API in Python

WIP: this library is still in early development phase.

jsonapy is a Python library for dumping models into JSON:API-compliant JSON.

PyPi Python Version Tests & coverage codecov

Installation

With pip:

pip install jsonapy

Basic usage overview

This package lets you define models and dump them into dict with the JSON:API structure. First, define a resource:

import jsonapy

class PersonResource(jsonapy.BaseResource):
    id: int
    first_name: str
    last_name: str

    class Meta:
        resource_name = "person"

You can now dump an instance of this resource into JSON:API-structured dictionary:

guido = PersonResource(id=1, first_name="Guido", last_name="Van Rossum")
data = guido.jsonapi_dict(required_attributes="__all__")

The resulting data dictionary can be represented by:

{
    'type': 'person',
    'id': 1,
    'attributes': {
        'firstName': 'Guido', 
        'lastName': 'Van Rossum'
    }
}

The complete documentation can be found here. It is built with pdoc.

Refer to the project to view the roadmap-related issues.