Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Helpers for handling jsonhome documents

Project description

Helpers for handling jsonhome documents

Introduction

The jsonhome library provides a simple way to build and consume compliant json-home documents.

Building

To build a jsonhome document you create a document and then add resources:

>>> import jsonhome

>>> doc = jsonhome.Document()

>>> doc.add_resource('http://mysite.com/rel/widgets',
...                  uri='/widgets{/widget_id}'
...                  uri_vars={'widget_id': 'http://mysite.com/param/widget'},
...                  allow_get=True,
...                  accept_post=['application/json'])

>>> print(doc.to_json())
{
    "resources": {
        "http://mysite.com/rel/widgets": {
            "href-template": "/widgets{/widget_id}",
            "href-vars": {
                "widget_id": "http://mysite.com/param/widget"
            },
            "hints": {
                "accept-post": [
                    "application/json"
                ],
                "allow": [
                    "GET",
                    "POST"
                ]
            }
        }
    }
}

Additional parameters to creating resources can be found on the module documentation.

Consuming

To consume a json-home document you load it and then fetch the URIs you need:

>>> doc = jsonhome.Document.from_json(data)

>>> print(doc.get_uri('http://mysite.com/rel/widgets', widget_id='1234')
'/widgets/1234'

Or for specific information you can find helpers on the resource:

>>> print(doc['http://mysite.com/rel/widgets'].href_vars)
{"widget_id": "http://mysite.com/param/widget"}

Project details


Release history Release notifications

This version
History Node

0.1.0

History Node

0.0.0.post8

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
jsonhome-0.1.0-py2.py3-none-any.whl (12.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Jul 25, 2015
jsonhome-0.1.0.tar.gz (15.7 kB) Copy SHA256 hash SHA256 Source None Jul 25, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page