README.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ==========
  2. jsonschema
  3. ==========
  4. |PyPI| |Pythons| |Travis| |AppVeyor| |Codecov| |ReadTheDocs|
  5. .. |PyPI| image:: https://img.shields.io/pypi/v/jsonschema.svg
  6. :alt: PyPI version
  7. :target: https://pypi.org/project/jsonschema/
  8. .. |Pythons| image:: https://img.shields.io/pypi/pyversions/jsonschema.svg
  9. :alt: Supported Python versions
  10. :target: https://pypi.org/project/jsonschema/
  11. .. |Travis| image:: https://travis-ci.com/Julian/jsonschema.svg?branch=master
  12. :alt: Travis build status
  13. :target: https://travis-ci.com/Julian/jsonschema
  14. .. |AppVeyor| image:: https://ci.appveyor.com/api/projects/status/adtt0aiaihy6muyn/branch/master?svg=true
  15. :alt: AppVeyor build status
  16. :target: https://ci.appveyor.com/project/Julian/jsonschema
  17. .. |Codecov| image:: https://codecov.io/gh/Julian/jsonschema/branch/master/graph/badge.svg
  18. :alt: Codecov Code coverage
  19. :target: https://codecov.io/gh/Julian/jsonschema
  20. .. |ReadTheDocs| image:: https://readthedocs.org/projects/python-jsonschema/badge/?version=stable&style=flat
  21. :alt: ReadTheDocs status
  22. :target: https://python-jsonschema.readthedocs.io/en/stable/
  23. ``jsonschema`` is an implementation of `JSON Schema <https://json-schema.org>`_
  24. for Python (supporting 2.7+ including Python 3).
  25. .. code-block:: python
  26. >>> from jsonschema import validate
  27. >>> # A sample schema, like what we'd get from json.load()
  28. >>> schema = {
  29. ... "type" : "object",
  30. ... "properties" : {
  31. ... "price" : {"type" : "number"},
  32. ... "name" : {"type" : "string"},
  33. ... },
  34. ... }
  35. >>> # If no exception is raised by validate(), the instance is valid.
  36. >>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema)
  37. >>> validate(
  38. ... instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema,
  39. ... ) # doctest: +IGNORE_EXCEPTION_DETAIL
  40. Traceback (most recent call last):
  41. ...
  42. ValidationError: 'Invalid' is not of type 'number'
  43. It can also be used from console:
  44. .. code-block:: bash
  45. $ jsonschema -i sample.json sample.schema
  46. Features
  47. --------
  48. * Full support for
  49. `Draft 7 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft7Validator>`_,
  50. `Draft 6 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft6Validator>`_,
  51. `Draft 4 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft4Validator>`_
  52. and
  53. `Draft 3 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft3Validator>`_
  54. * `Lazy validation <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.IValidator.iter_errors>`_
  55. that can iteratively report *all* validation errors.
  56. * `Programmatic querying <https://python-jsonschema.readthedocs.io/en/latest/errors/>`_
  57. of which properties or items failed validation.
  58. Installation
  59. ------------
  60. ``jsonschema`` is available on `PyPI <https://pypi.org/project/jsonschema/>`_. You can install using `pip <https://pip.pypa.io/en/stable/>`_:
  61. .. code-block:: bash
  62. $ pip install jsonschema
  63. Demo
  64. ----
  65. Try ``jsonschema`` interactively in this online demo:
  66. .. image:: https://user-images.githubusercontent.com/1155573/56745335-8b158a00-6750-11e9-8776-83fa675939c4.png
  67. :target: https://notebooks.ai/demo/gh/Julian/jsonschema
  68. :alt: Open Live Demo
  69. Online demo Notebook will look similar to this:
  70. .. image:: https://user-images.githubusercontent.com/1155573/56820861-5c1c1880-6823-11e9-802a-ce01c5ec574f.gif
  71. :alt: Open Live Demo
  72. :width: 480 px
  73. Release Notes
  74. -------------
  75. v3.1 brings support for ECMA 262 dialect regular expressions
  76. throughout schemas, as recommended by the specification. Big
  77. thanks to @Zac-HD for authoring support in a new `js-regex
  78. <https://pypi.org/project/js-regex/>`_ library.
  79. Running the Test Suite
  80. ----------------------
  81. If you have ``tox`` installed (perhaps via ``pip install tox`` or your
  82. package manager), running ``tox`` in the directory of your source
  83. checkout will run ``jsonschema``'s test suite on all of the versions
  84. of Python ``jsonschema`` supports. If you don't have all of the
  85. versions that ``jsonschema`` is tested under, you'll likely want to run
  86. using ``tox``'s ``--skip-missing-interpreters`` option.
  87. Of course you're also free to just run the tests on a single version with your
  88. favorite test runner. The tests live in the ``jsonschema.tests`` package.
  89. Benchmarks
  90. ----------
  91. ``jsonschema``'s benchmarks make use of `pyperf
  92. <https://pyperf.readthedocs.io>`_.
  93. Running them can be done via ``tox -e perf``, or by invoking the ``pyperf``
  94. commands externally (after ensuring that both it and ``jsonschema`` itself are
  95. installed)::
  96. $ python -m pyperf jsonschema/benchmarks/test_suite.py --hist --output results.json
  97. To compare to a previous run, use::
  98. $ python -m pyperf compare_to --table reference.json results.json
  99. See the ``pyperf`` documentation for more details.
  100. Community
  101. ---------
  102. There's a `mailing list <https://groups.google.com/forum/#!forum/jsonschema>`_
  103. for this implementation on Google Groups.
  104. Please join, and feel free to send questions there.
  105. Contributing
  106. ------------
  107. I'm Julian Berman.
  108. ``jsonschema`` is on `GitHub <https://github.com/Julian/jsonschema>`_.
  109. Get in touch, via GitHub or otherwise, if you've got something to contribute,
  110. it'd be most welcome!
  111. You can also generally find me on Freenode (nick: ``tos9``) in various
  112. channels, including ``#python``.
  113. If you feel overwhelmingly grateful, you can also woo me with beer money
  114. via Google Pay with the email in my GitHub profile.
  115. And for companies who appreciate ``jsonschema`` and its continued support
  116. and growth, ``jsonschema`` is also now supportable via `TideLift
  117. <https://tidelift.com/subscription/pkg/pypi-jsonschema?utm_source=pypi-j
  118. sonschema&utm_medium=referral&utm_campaign=readme>`_.