Skip to main content

JavaScript Resource Notation for Python

Project description

This library has been deprecated in favour of Odin

A JSON based notation for resources that can be easily converted into object graphs.

Travis CI Status

Highlights

  • Class based declarative style

  • Support for all JSON primitive types (including JavaScript Date)

  • Fields for building composite resources

  • Field and Resource level validation

  • Easy extension to support custom fields

  • Python 2.7+ and Python 3.3+ supported

Upcoming features

In development

  • Customisable generation of documentation of resources (for integration into Sphinx)

  • Complete documentation (around 70-80% complete for current features)

Planning

  • Integration with other libraries (ie Django Models/Forms)

Requires

  • six

Optional

  • jinja2 >= 2.7 - For documentation generation

  • simplejson - Performance improvements

Example

With definition:

import jsrn

class Author(jsrn.Resource):
    name = jsrn.StringField()

class Publisher(jsrn.Resource):
    name = jsrn.StringField()

class Book(jsrn.Resource):
    title = jsrn.StringField()
    authors = jsrn.ArrayOf(Author)
    publisher = jsrn.ObjectAs(Publisher)
    genre = jsrn.StringField()
    num_pages = jsrn.IntegerField()
>>> b = Book(
        title="Consider Phlebas",
        genre="Space Opera",
        publisher=Publisher(name="Macmillan"),
        num_pages=471
    )
>>> b.authors.append(Author(name="Iain M. Banks"))
>>> jsrn.dumps(b, pretty_print=True)
{
    "$": "Book",
    "authors": [
        {
            "$": "Author",
            "name": "Iain M. Banks"
        }
    ],
    "genre": "Space Opera",
    "num_pages": 471,
    "publisher": {
        "$": "Publisher",
        "name": "Macmillan"
    },
    "title": "Consider Phlebas"
}

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

jsrn-0.3.2.tar.gz (13.7 kB view details)

Uploaded Source

File details

Details for the file jsrn-0.3.2.tar.gz.

File metadata

  • Download URL: jsrn-0.3.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsrn-0.3.2.tar.gz
Algorithm Hash digest
SHA256 cf8361577b278e172355317980070be30421cade5f9c2d219830babc511594aa
MD5 f2b38b914e997eeb3da9698e7f2240f9
BLAKE2b-256 6eabfc820d483dead1c68d2a713729e2b50952f9e216ae636f7143274895cb74

See more details on using hashes here.

Supported by

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