Skip to main content

JSON:API ORM

https://img.shields.io/pypi/v/jsonapi_orm.svg https://img.shields.io/travis/mislavcimpersak/jsonapi_orm.svg Documentation Status

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

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:

pip install requests
pip install jsonapi-orm

Switch to your Python code and use the magic!

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.

History

0.1.6 (2018-03-25)

  • Readme fix for pypi.

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonapi-orm-0.1.6.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

jsonapi_orm-0.1.6-py2.py3-none-any.whl (4.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file jsonapi-orm-0.1.6.tar.gz.

File metadata

  • Download URL: jsonapi-orm-0.1.6.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonapi-orm-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a3906b7b0f8237e7604c0438dadec0f55a99f9f885ffed35f5b4a66649f5eb06
MD5 678edddcfc194a38e2ed3c230c56e51a
BLAKE2b-256 24900b36f12cc309df88f68dd48263b349eefea41ee02e53f9a636f08a88743f

See more details on using hashes here.

File details

Details for the file jsonapi_orm-0.1.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jsonapi_orm-0.1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 87f1e68594cd77e986017183e2b35c370682bbe27d55826a2ab82f46157f4da8
MD5 a6cefeb72a5eae59f214b654772b0261
BLAKE2b-256 b6d76d369bf13365fa5f2d9a0d2a3d5e7cc7756dce081ccfc283db7ac50a093a

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.8

2 files

0.1.7

2 files

This release

0.1.6 This release

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.0

2 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