Skip to main content

Fast JSON Schema validation for Python implemented in Rust

Project description

Build Version Python versions License

Fast JSON Schema validation for Python implemented in Rust.

Supported drafts:

  • Draft 7

  • Draft 6

  • Draft 4

There are some notable restrictions at the moment:

  • The underlying crate doesn’t support arbitrary precision integers yet, which may lead to SystemError when such value is used;

  • multipleOf keyword validation may produce false-negative results on some input. See #84 for more details

Installation

To install jsonschema-rs via pip run the following command:

pip install jsonschema-rs

Usage

To check if the input document is valid:

import jsonschema_rs

validator = jsonschema_rs.JSONSchema({"minimum": 42})
validator.is_valid(45)  # True

or:

import jsonschema_rs

validator = jsonschema_rs.JSONSchema({"minimum": 42})
validator.validate(41)  # raises ValidationError

NOTE. This library is in early development.

Performance

According to our benchmarks, jsonschema-rs is usually faster than existing alternatives in real-life scenarios.

However, for small schemas & inputs it might be slower than fastjsonschema or jsonschema on PyPy.

Input values and schemas

Case

Schema size

Instance size

OpenAPI

18 KB

4.5 MB

Swagger

25 KB

3.0 MB

Canada

4.8 KB

2.1 MB

CITM catalog

2.3 KB

501 KB

Fast (valid)

595 B

55 B

Fast (invalid)

595 B

60 B

Compiled validators (when the input schema is compiled once and reused later). jsonschema-rs comes in three variants in the tables below:

  • validate. This method raises ValidationError on errors or returns None on their absence.

  • is_valid. A faster method that returns a boolean result whether the instance is valid.

  • overhead. Only transforms data to underlying Rust types and do not perform any validation. Shows the Python -> Rust data conversion cost.

Ratios are given against the validate variant.

Small schemas:

library

true

{"minimum": 10}

Fast (valid)

Fast (invalid)

jsonschema-rs[validate]

80.83 ns

86.23 ns

982.01 ns

1.54 us

jsonschema-rs[is_valid]

68.29 ns (x0.84)

71.66 ns (x0.83)

650.68 ns (x0.66)

1.25 us (x0.81)

jsonschema-rs[overhead]

65.27 ns (x0.81)

66.90 ns (x0.78)

461.53 ns (x0.47)

925.16 ns (x0.60)

fastjsonschema[CPython]

58.57 ns (x0.72)

109.10 ns (x1.27)

4.16 us (x4.24)

4.75 us (x3.08)

fastjsonschema[PyPy]

1.32 ns (x0.02)

33.39 ns (x0.39)

890 ns (x0.91)

875 ns (x0.57)

jsonschema[CPython]

226.48 ns (x2.80)

1.88 us (x21.8)

56.58 us (x57.62)

57.31 us (x37.21)

jsonschema[PyPy]

41.18 ns (x0.51)

224.94 ns (x2.61)

23.40 us (x23.83)

22.78 us (x14.79)

Large schemas:

library

Zuora (OpenAPI)

Kubernetes (Swagger)

Canada (GeoJSON)

CITM catalog

jsonschema-rs[validate]

17.431 ms

13.861 ms

4.782 ms

4.551 ms

jsonschema-rs[is_valid]

16.732 ms (x0.96)

12.174 ms (x0.88)

4.591 ms (x0.96)

2.935 ms (x0.64)

jsonschema-rs[overhead]

12.017 ms (x0.69)

8.005 ms (x0.58)

3.702 ms (x0.77)

2.303 ms (x0.51)

fastjsonschema[CPython]

– (1)

87.020 ms (x6.28)

31.705 ms (6.63)

11.715 ms (x2.57)

fastjsonschema[PyPy]

– (1)

38.586 ms (x2.78)

8.417 ms (x1.76)

4.789 ms (x1.05)

jsonschema[CPython]

749.615 ms (x43.00)

1.032 s (x74.45)

1.286 s (x268.93)

112.510 ms (x24.72)

jsonschema[PyPy]

611.056 ms (x35.06)

592.584 ms (x42.75)

530.567 ms (x110.95)

28.619 ms (x6.07)

Notes:

  1. fastjsonschema fails to compile the Open API spec due to the presence of the uri-reference format (that is not defined in Draft 4). However, unknown formats are explicitly supported by the spec.

The bigger the input is the bigger is performance win. You can take a look at benchmarks in benches/bench.py.

Package versions:

  • jsonschema-rs - latest version from the repository

  • jsonschema - 3.2.0

  • fastjsonschema - 2.15.0

Measured with stable Rust 1.51, CPython 3.9.4 / PyPy3 7.3.4 on i8700K (12 cores), 32GB RAM, Arch Linux.

Python support

jsonschema-rs supports CPython 3.6, 3.7, 3.8 and 3.9.

License

The code in this project is licensed under MIT license. By contributing to jsonschema-rs, you agree that your contributions will be licensed under its MIT license.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

jsonschema_rs-0.12.1.tar.gz (67.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jsonschema_rs-0.12.1-cp39-cp39-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.12.1-cp39-cp39-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

jsonschema_rs-0.12.1-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.12.1-cp38-cp38-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

jsonschema_rs-0.12.1-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.12.1-cp37-cp37m-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

jsonschema_rs-0.12.1-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.12.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.12.1-cp36-cp36m-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

File details

Details for the file jsonschema_rs-0.12.1.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.12.1.tar.gz
  • Upload date:
  • Size: 67.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1.tar.gz
Algorithm Hash digest
SHA256 c062b712dc157cb5c232b4ded88c72e8059d696e5226ba13ab3c0b822f58d66e
MD5 53b55712afcb358a80a8ca3520e22449
BLAKE2b-256 dae4815f04aef807442154d764bdba7820beeb1359071954702cb6d5e2f7ca7a

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6d2a72f4b75bc7c0b1564be6214f9dced6a796d54a5fe5f576a334cdd1654f08
MD5 4bdc535bad45afe312c91eee2c0866fe
BLAKE2b-256 27042a70343286b94fc5a4f33ef276d9e2b0b4d37c916251f2ed4c4d14429ae1

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6edbb7f7320734bc391f49897ea4f482821a92d7479dce9a43515c3a0e8c1fce
MD5 f2ca6ac37586a15c5c76a5b527f77de1
BLAKE2b-256 a2e1db4d728b3cbe91254417faf59707ffd821c60b6db158851aefae19a69fcf

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0d145eba335cb18c54f35cbdababeb8d085e397a8f70ae198a1089ab245aca29
MD5 8791b375c4793609a901799875fed1b3
BLAKE2b-256 5fbf0e408c03ee113fd4eb602f564b8d2c27e6c75afe7b6fe4e3f26893b469dc

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4beba61e4be72a279c6b2f905ab9ac03e8569dcd7dc9f9bd3ab9ff5aafb7d330
MD5 7c0c56ba55acb5134b5a463c3a399fe2
BLAKE2b-256 9f21868dc90fc9774739c4542986515fbb01b2b856d0da3b55f3fdf2d9c14cd1

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24faf8673cf52816fe80718bac58cfe49bdc58dbcba921e57ea6e6f2fdcf8244
MD5 26bbe4d3f84d8bb370ddbb464ec513e1
BLAKE2b-256 b9ce81e64bb70f46b8e38f5d18001ccf1e921de16b28d005bf46228f16d11e48

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 389c2a1fd824da323c707b134970299502ce5d6fe26c0ee4a8f2deb17fed7174
MD5 4f7847e108b33ceb591f4ceb546e1411
BLAKE2b-256 37edff4e4f4156d167716baded00c6f38524dc90bb3708ef485299836c8065b2

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 12d82d07429a7905989491f6985cc27c483ef82431e33241ed865260f469037c
MD5 e0245f38316cc2fba29df139261f188f
BLAKE2b-256 de1486cc03bc66ab9f9908ca480bd0c76d2f4b56d45b237fa5e77aeff8407db0

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4551a55626d4418acbb9e3614e7515ba4c38fe3f80d39e481412f0f2aec459a8
MD5 e73201dd45fce2ee700479762486ade2
BLAKE2b-256 1fee9f49eedaa0b040e8c2fbfe5b01e97b4baffadeb4fdc8694f22c91f569093

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f5d5de7361a71ce46b2d1bac2b4464e51d608454a7ffa2b0ebde8d45cbc40dbc
MD5 8fb7e599c4e246c7fd938087360d73da
BLAKE2b-256 ca9cf09ea5b7fc1b818af5be821a5ca89682ba3d04d40df22733ffe2821a2b21

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b3b8520e1100705bd8539ffb38b294674f91314296657eebff9492e822998829
MD5 611fd1281afa5317ae2beb0943a71e18
BLAKE2b-256 3179250ae757dd3570cc17459e4f5941fd970ea966c192cb8bc7952d0b4768c4

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.12.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ba0a7b44438adb32a00db09607aafeb7d0006d33559984a8e4419cdf9a07870
MD5 4e5f3af6fee72909330cc077cbdf68b9
BLAKE2b-256 053545816f8631cb24f79f698a70a062e17995a4422ba6bc249fa245c596658e

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.12.1-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.12.1-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.12.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a8593c95d6966b0b18749f4ee55abf439d673bacc2bcfb17dec63c25e87f037d
MD5 44a950ce96bf08a2228cf497e45119c4
BLAKE2b-256 00334d0f8dd8c560e39814505d4a51f54182e1c1a2abd6625ff748bd1219a8a2

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