rxjson


Namerxjson JSON
Version 0.3 PyPI version JSON
download
home_pagehttps://github.com/spiral-project/rxjson
SummaryJSON RX Schema validation tool
upload_time2015-06-12 12:15:24
maintainerNone
docs_urlNone
authorRémy Hubscher
requires_pythonNone
licenseGPLv2.0
keywords json schema validation rx rxjson
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            What is Rx?
===========

When adding an API to your web service, you have to choose how to encode the
data you send across the line. XML is one common choice for this, but it can
grow arcane and cumbersome pretty quickly. Lots of webservice authors want to
avoid thinking about XML, and instead choose formats that provide a few simple
data types that correspond to common data structures in modern programming
languages. In other words, JSON and YAML.

Unfortunately, while these formats make it easy to pass around complex data
structures, they lack a system for validation. XML has XML Schemas and RELAX
NG, but these are complicated and sometimes confusing standards. They're not
very portable to the kind of data structure provided by JSON, and if you wanted
to avoid XML as a data encoding, writing more XML to validate the first XML is
probably even less appealing.

Rx is meant to provide a system for data validation that matches up with
JSON-style data structures and is as easy to work with as JSON itself.

rxjson
======

rxjson is a python package that helps you validate your generated JSON
against a standardized json schema directly in your python app.

It is a packaged version of http://rx.codesimply.com/

.. image:: https://secure.travis-ci.org/spiral-project/rxjson.png
   :target: http://travis-ci.org/spiral-project/rxjson/
   :alt: Travis-ci: continuous integration status.

Usage
=====

Here is a little example of how to validate your json against a rx schema:

.. code-block:: python

    import requests
    from rxjson import Rx
    import unittest
    
    class SporeTest(unittest.TestCase):
        """Test generate spore schema."""
        def test_spore(self):
            rx = Rx.Factory({ "register_core_types": True })
            with open('spore_validation.rx') as f:
                spore_json_schema = json.loads(f.read())
                spore_schema = rx.make_schema(spore_json_schema)
                resp = requests.get('http://localhost:8000/spore', headers={'Content-Type': 'application/json'})
                self.assertTrue(spore_schema.check(resp.json))

Or even quicker:

.. code-block:: python

    >>> import json
    >>> from rxjson import Rx
    >>> rx = Rx.Factory({ "register_core_types": True })
    >>> spore_json_schema = json.loads(open('spore_validation.rx').read())
    >>> spore_schema = rx.make_schema(spore_json_schema)
    >>> js = json.loads("""{
    ...     "base_url": "http://localhost:8000",
    ...     "expected_status": [200],
    ...     "version": "0.1",
    ...     "methods": {
    ...         "put_data_item": {
    ...             "path": "/data/:model_name/:data_item_id",
    ...             "description": "Update a data item.",
    ...             "required_params": ["model_name", "data_item_id"],
    ...             "method": "PUT",
    ...             "formats": ["json"]
    ...         }
    ...     },
    ...     "name": "daybed"
    ... }""")
    >>> spore_schema.check(js)
    True

* ``spore_validation.rx`` is part of https://github.com/SPORE/specifications
* ``daybed`` is a form model validation API: https://github.com/spiral-project/daybed
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/spiral-project/rxjson",
    "name": "rxjson",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "json schema validation rx rxjson",
    "author": "R\u00e9my Hubscher",
    "author_email": "hubscher.remy@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0a/66/a34442065708bf6416af43d6285129b5b806eecee2f04926f63998eda170/rxjson-0.3.zip",
    "platform": "UNKNOWN",
    "description": "What is Rx?\n===========\n\nWhen adding an API to your web service, you have to choose how to encode the\ndata you send across the line. XML is one common choice for this, but it can\ngrow arcane and cumbersome pretty quickly. Lots of webservice authors want to\navoid thinking about XML, and instead choose formats that provide a few simple\ndata types that correspond to common data structures in modern programming\nlanguages. In other words, JSON and YAML.\n\nUnfortunately, while these formats make it easy to pass around complex data\nstructures, they lack a system for validation. XML has XML Schemas and RELAX\nNG, but these are complicated and sometimes confusing standards. They're not\nvery portable to the kind of data structure provided by JSON, and if you wanted\nto avoid XML as a data encoding, writing more XML to validate the first XML is\nprobably even less appealing.\n\nRx is meant to provide a system for data validation that matches up with\nJSON-style data structures and is as easy to work with as JSON itself.\n\nrxjson\n======\n\nrxjson is a python package that helps you validate your generated JSON\nagainst a standardized json schema directly in your python app.\n\nIt is a packaged version of http://rx.codesimply.com/\n\n.. image:: https://secure.travis-ci.org/spiral-project/rxjson.png\n   :target: http://travis-ci.org/spiral-project/rxjson/\n   :alt: Travis-ci: continuous integration status.\n\nUsage\n=====\n\nHere is a little example of how to validate your json against a rx schema:\n\n.. code-block:: python\n\n    import requests\n    from rxjson import Rx\n    import unittest\n    \n    class SporeTest(unittest.TestCase):\n        \"\"\"Test generate spore schema.\"\"\"\n        def test_spore(self):\n            rx = Rx.Factory({ \"register_core_types\": True })\n            with open('spore_validation.rx') as f:\n                spore_json_schema = json.loads(f.read())\n                spore_schema = rx.make_schema(spore_json_schema)\n                resp = requests.get('http://localhost:8000/spore', headers={'Content-Type': 'application/json'})\n                self.assertTrue(spore_schema.check(resp.json))\n\nOr even quicker:\n\n.. code-block:: python\n\n    >>> import json\n    >>> from rxjson import Rx\n    >>> rx = Rx.Factory({ \"register_core_types\": True })\n    >>> spore_json_schema = json.loads(open('spore_validation.rx').read())\n    >>> spore_schema = rx.make_schema(spore_json_schema)\n    >>> js = json.loads(\"\"\"{\n    ...     \"base_url\": \"http://localhost:8000\",\n    ...     \"expected_status\": [200],\n    ...     \"version\": \"0.1\",\n    ...     \"methods\": {\n    ...         \"put_data_item\": {\n    ...             \"path\": \"/data/:model_name/:data_item_id\",\n    ...             \"description\": \"Update a data item.\",\n    ...             \"required_params\": [\"model_name\", \"data_item_id\"],\n    ...             \"method\": \"PUT\",\n    ...             \"formats\": [\"json\"]\n    ...         }\n    ...     },\n    ...     \"name\": \"daybed\"\n    ... }\"\"\")\n    >>> spore_schema.check(js)\n    True\n\n* ``spore_validation.rx`` is part of https://github.com/SPORE/specifications\n* ``daybed`` is a form model validation API: https://github.com/spiral-project/daybed",
    "bugtrack_url": null,
    "license": "GPLv2.0",
    "summary": "JSON RX Schema validation tool",
    "version": "0.3",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "https://github.com/spiral-project/rxjson"
    },
    "split_keywords": [
        "json",
        "schema",
        "validation",
        "rx",
        "rxjson"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a66a34442065708bf6416af43d6285129b5b806eecee2f04926f63998eda170",
                "md5": "e3dbc9b395193db1b76bd27344e4402d",
                "sha256": "2ed3d5dadf9e8aef2ef1f3cdfa3cf9abae99c9eac5a2db0267f17a9dae3a66e1"
            },
            "downloads": -1,
            "filename": "rxjson-0.3.zip",
            "has_sig": false,
            "md5_digest": "e3dbc9b395193db1b76bd27344e4402d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9694,
            "upload_time": "2015-06-12T12:15:24",
            "upload_time_iso_8601": "2015-06-12T12:15:24.378827Z",
            "url": "https://files.pythonhosted.org/packages/0a/66/a34442065708bf6416af43d6285129b5b806eecee2f04926f63998eda170/rxjson-0.3.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2015-06-12 12:15:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "spiral-project",
    "github_project": "rxjson",
    "github_not_found": true,
    "lcname": "rxjson"
}
        
Elapsed time: 0.08345s