Skip to main content

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


Download files

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

Source Distribution

jsonhome-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

jsonhome-0.1.0-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jsonhome-0.1.0.tar.gz.

File metadata

  • Download URL: jsonhome-0.1.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonhome-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0c2e04fd77a176acb7587b49a6275f75bee73d44f717690f39f2aa57f29f015
MD5 7930c61dea85e8ca89045ccf5f65951d
BLAKE2b-256 5a3a76ba53800e514a9867df415460b38ef4b3f7ea7769f811fdcaa07d3c2faa

See more details on using hashes here.

File details

Details for the file jsonhome-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jsonhome-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 36201a336ad96f6f07c44fb375c327176d8e0e2b5d35be145ba3c83cd564b9c5
MD5 f698d0ec8ec93a8c14a1f0c350216457
BLAKE2b-256 1f08737cc043fbd4b7e6d212474deb374edc80b0f60bd9ff343cc24dcfa02e27

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page