Skip to main content
============
JSON:API ORM
============


.. image:: https://img.shields.io/pypi/v/jsonapi_orm.svg
:target: https://pypi.python.org/pypi/jsonapi_orm

.. image:: https://img.shields.io/travis/mislavcimpersak/jsonapi_orm.svg
:target: https://travis-ci.org/mislavcimpersak/jsonapi_orm

.. image:: https://readthedocs.org/projects/jsonapi-orm/badge/?version=latest
:target: https://jsonapi-orm.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status




Quick and dirty ORM that maps JSON:API responses to object attributes.


* Free software: BSD license
* Documentation: https://jsonapi-orm.readthedocs.io.


How To
======

Use Requests_ or (if you are a masochist) Python's built-in urllib modules to make the request to your JSON:API service and from there pass the response to JSON:API ORM.

So, first install requests and this lib:

.. code-block:: bash

pip install requests
pip install jsonapi-orm

Switch to your Python code and use the magic!

.. code-block:: python

import requests
from jsonapi_orm import response_to_obj


# list of items
r = requests.get('https://raw.githubusercontent.com/mislavcimpersak/jsonapi-orm/master/tests/responses/example_list.json')
obj = response_to_obj(r.json())

print('LIST OF ITEMS:')
for item in obj.data:
print(item.title)
# author is defined as a relationship
print(item.author.twitter)


# single item
r = requests.get('https://raw.githubusercontent.com/mislavcimpersak/jsonapi-orm/master/tests/responses/example_single.json')
obj = response_to_obj(r.json())

print('SINGLE ITEM')
print(obj.data.title)
# author is defined as a relationship
print(obj.data.author.id)
print(obj.data.author.twitter)


Caveats
-------

* Since Python object attribute names `have certain rules`__ like not starting with a number or not containing "-" char, all such attributes can be accessed using ``.get()`` method. Ie. ``obj.data.author.get('first-name')``.

* If relationship is not described in more detail in the ``included`` part of the response matching fails silently.

* For now, this lib does not lazily follow relationship links or anything like that. You can of course make a new request to the given link and pass that response to JSON:API ORM.

* For now, there is no check if response is a valid JSON:API response. But you'll probably get that you are trying to parse an invalid response when things start to break.

* And last, this lib requires Python 3.5 or newer.


.. _Requests: http://docs.python-requests.org
.. _rules: https://docs.python.org/3/reference/lexical_analysis.html#identifiers

__ rules_


=======
History
=======

0.1.5 (2018-03-25)
------------------

* Readme fix for pypi.

0.1.4 (2018-03-25)
------------------

* Readme examples using slighty modified examples from jsonapi.org which are located in this repo.

0.1.3 (2018-03-25)
------------------

* Fixed a bug when child data is non-existent.

0.1.2 (2018-03-25)
------------------

* Fixed a bug when included is not present in response.

0.1.0 (2018-03-24)
------------------

* First release on PyPI.


Metadata

Release files for jsonapi-orm 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonapi-orm 0.1.5
File Size Uploaded
jsonapi-orm-0.1.5.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonapi-orm 0.1.5
File Interpreter ABI Platform
jsonapi_orm-0.1.5-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.9 kB

Release files / jsonapi-orm-0.1.5.tar.gz

Download URL jsonapi-orm-0.1.5.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4dcff668a2582eff8d006960358eaaba10c287fd75a55f4616afa95adf100ce8
BLAKE2b-256 checksum
How to use checksums
9cfc9483737e1743048d192682d1b0147da28a414f0ecf4dee6c7189c56c6fd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / jsonapi_orm-0.1.5-py2.py3-none-any.whl

Download URL jsonapi_orm-0.1.5-py2.py3-none-any.whl
Size 4.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
edd9c51e792eef1da475fb7a1f84dcdba659ab813b20852b4fe7fece554f6ddf
BLAKE2b-256 checksum
How to use checksums
7c5d4aae076fbb40589c5f9771bfbd201b72dd42e4f358af5d552cd291437c6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page