|
Packit |
534379 |
Metadata-Version: 1.1
|
|
Packit |
534379 |
Name: jsonschema
|
|
Packit |
534379 |
Version: 2.3.0
|
|
Packit |
534379 |
Summary: An implementation of JSON Schema validation for Python
|
|
Packit |
534379 |
Home-page: http://github.com/Julian/jsonschema
|
|
Packit |
534379 |
Author: Julian Berman
|
|
Packit |
534379 |
Author-email: Julian@GrayVines.com
|
|
Packit |
534379 |
License: MIT
|
|
Packit |
534379 |
Description: ==========
|
|
Packit |
534379 |
jsonschema
|
|
Packit |
534379 |
==========
|
|
Packit |
534379 |
|
|
Packit |
534379 |
``jsonschema`` is an implementation of `JSON Schema <http://json-schema.org>`_
|
|
Packit |
534379 |
for Python (supporting 2.6+ including Python 3).
|
|
Packit |
534379 |
|
|
Packit |
534379 |
.. code-block:: python
|
|
Packit |
534379 |
|
|
Packit |
534379 |
>>> from jsonschema import validate
|
|
Packit |
534379 |
|
|
Packit |
534379 |
>>> # A sample schema, like what we'd get from json.load()
|
|
Packit |
534379 |
>>> schema = {
|
|
Packit |
534379 |
... "type" : "object",
|
|
Packit |
534379 |
... "properties" : {
|
|
Packit |
534379 |
... "price" : {"type" : "number"},
|
|
Packit |
534379 |
... "name" : {"type" : "string"},
|
|
Packit |
534379 |
... },
|
|
Packit |
534379 |
... }
|
|
Packit |
534379 |
|
|
Packit |
534379 |
>>> # If no exception is raised by validate(), the instance is valid.
|
|
Packit |
534379 |
>>> validate({"name" : "Eggs", "price" : 34.99}, schema)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
>>> validate(
|
|
Packit |
534379 |
... {"name" : "Eggs", "price" : "Invalid"}, schema
|
|
Packit |
534379 |
... ) # doctest: +IGNORE_EXCEPTION_DETAIL
|
|
Packit |
534379 |
Traceback (most recent call last):
|
|
Packit |
534379 |
...
|
|
Packit |
534379 |
ValidationError: 'Invalid' is not of type 'number'
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Features
|
|
Packit |
534379 |
--------
|
|
Packit |
534379 |
|
|
Packit |
534379 |
* Full support for
|
|
Packit |
534379 |
`Draft 3 <https://python-jsonschema.readthedocs.org/en/latest/validate.html#jsonschema.Draft3Validator>`_
|
|
Packit |
534379 |
**and** `Draft 4 <https://python-jsonschema.readthedocs.org/en/latest/validate.html#jsonschema.Draft4Validator>`_
|
|
Packit |
534379 |
of the schema.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
* `Lazy validation <https://python-jsonschema.readthedocs.org/en/latest/validate.html#jsonschema.IValidator.iter_errors>`_
|
|
Packit |
534379 |
that can iteratively report *all* validation errors.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
* Small and extensible
|
|
Packit |
534379 |
|
|
Packit |
534379 |
* `Programmatic querying <https://python-jsonschema.readthedocs.org/en/latest/errors.html#module-jsonschema>`_
|
|
Packit |
534379 |
of which properties or items failed validation.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Release Notes
|
|
Packit |
534379 |
-------------
|
|
Packit |
534379 |
|
|
Packit |
534379 |
``v2.3.0`` removes the (improper) limitation of ``format`` to strings. It also
|
|
Packit |
534379 |
adds the `jsonschema.exceptions.best_match <https://python-jsonschema.readthedocs.org/en/latest/errors/#best-match-and-by-relevance>`_
|
|
Packit |
534379 |
function which can be used to guess at the best matching single validation
|
|
Packit |
534379 |
error for a given instance.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
.. code-block:: python
|
|
Packit |
534379 |
|
|
Packit |
534379 |
>>> from jsonschema.validators import Draft4Validator
|
|
Packit |
534379 |
>>> from jsonschema.exceptions import best_match
|
|
Packit |
534379 |
|
|
Packit |
534379 |
>>> schema = {
|
|
Packit |
534379 |
... "properties" : {
|
|
Packit |
534379 |
... "foo" : {"type" : "string"},
|
|
Packit |
534379 |
... "bar" : {"properties" : {"baz": {"type": "string"}}},
|
|
Packit |
534379 |
... },
|
|
Packit |
534379 |
... }
|
|
Packit |
534379 |
>>> instance = {"foo" : 12, "bar": {"baz" : 19}}
|
|
Packit |
534379 |
>>> print(best_match(Draft4Validator(schema).iter_errors(instance)).path)
|
|
Packit |
534379 |
deque(['foo'])
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
where the error closer to the top of the instance in ``foo`` was selected
|
|
Packit |
534379 |
as being more relevant.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Also, URI references are now properly rejected by the URI format validator
|
|
Packit |
534379 |
(i.e., it now only accepts full URIs, as defined in the specification).
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Running the Test Suite
|
|
Packit |
534379 |
----------------------
|
|
Packit |
534379 |
|
|
Packit |
534379 |
``jsonschema`` uses the wonderful `Tox <http://tox.readthedocs.org>`_ for its
|
|
Packit |
534379 |
test suite. (It really is wonderful, if for some reason you haven't heard of
|
|
Packit |
534379 |
it, you really should use it for your projects).
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Assuming you have ``tox`` installed (perhaps via ``pip install tox`` or your
|
|
Packit |
534379 |
package manager), just run ``tox`` in the directory of your source checkout to
|
|
Packit |
534379 |
run ``jsonschema``'s test suite on all of the versions of Python ``jsonschema``
|
|
Packit |
534379 |
supports. Note that you'll need to have all of those versions installed in
|
|
Packit |
534379 |
order to run the tests on each of them, otherwise ``tox`` will skip (and fail)
|
|
Packit |
534379 |
the tests on that version.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Of course you're also free to just run the tests on a single version with your
|
|
Packit |
534379 |
favorite test runner. The tests live in the ``jsonschema.tests`` package.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Community
|
|
Packit |
534379 |
---------
|
|
Packit |
534379 |
|
|
Packit |
534379 |
There's a `mailing list <https://groups.google.com/forum/#!forum/jsonschema>`_
|
|
Packit |
534379 |
for this implementation on Google Groups.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Please join, and feel free to send questions there.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Contributing
|
|
Packit |
534379 |
------------
|
|
Packit |
534379 |
|
|
Packit |
534379 |
I'm Julian Berman.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
``jsonschema`` is on `GitHub <http://github.com/Julian/jsonschema>`_.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Get in touch, via GitHub or otherwise, if you've got something to contribute,
|
|
Packit |
534379 |
it'd be most welcome!
|
|
Packit |
534379 |
|
|
Packit |
534379 |
You can also generally find me on Freenode (nick: ``tos9``) in various
|
|
Packit |
534379 |
channels, including ``#python``.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
If you feel overwhelmingly grateful, you can woo me with beer money on
|
|
Packit |
534379 |
`Gittip <https://www.gittip.com/Julian/>`_ or via Google Wallet with the email
|
|
Packit |
534379 |
in my GitHub profile.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
Platform: UNKNOWN
|
|
Packit |
534379 |
Classifier: Development Status :: 5 - Production/Stable
|
|
Packit |
534379 |
Classifier: Intended Audience :: Developers
|
|
Packit |
534379 |
Classifier: License :: OSI Approved :: MIT License
|
|
Packit |
534379 |
Classifier: Operating System :: OS Independent
|
|
Packit |
534379 |
Classifier: Programming Language :: Python
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 2
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 2.6
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 2.7
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 3
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 3.1
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 3.2
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: 3.3
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
Packit |
534379 |
Classifier: Programming Language :: Python :: Implementation :: PyPy
|