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.0.tar.gz (67.3 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.0-cp39-cp39-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.12.0-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.0-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.0-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.12.0-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.0-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.0-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.12.0-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.0-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.0-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.12.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.12.0.tar.gz
  • Upload date:
  • Size: 67.3 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.0.tar.gz
Algorithm Hash digest
SHA256 61550b8869efd3881d363a21ec46e101926550327a3e2c7288134591f1fff9ea
MD5 c2dab6cae2febb71d03ca7e411d93811
BLAKE2b-256 bd8d95325915d77007e49f79479469706cca0bd30bd5d7d5950cc663d6904e63

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 bb1fa01e2f34adb85341bd1998e65b4fd85ff7b7a3f8fd73a0f179bafa2902cb
MD5 1472540216bb143624ad5a8d9e5eb40d
BLAKE2b-256 4d66265c113cf21816d7b83b0ca3527587ae53a0822b6a808f97ca470e68e9de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff11d36c3da342770a2b4598fb62e00ca6fe2479c1a7541433bfff1f4848d777
MD5 e8456bbad355961c8f96dfe2d14f7119
BLAKE2b-256 29728ff494d2f5d5c2c14347a560bc5f05f364d7e01c82f3f9f7e45796b17e61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 826f42b9993e759fce077203b9811a7b789eb2566e58e08f87ad0d86035e0f58
MD5 a9328dba9c666e3a2b9308b7ae2d3b16
BLAKE2b-256 947d085ae4d532e6808848b28a85d8e3f1af67693da3c80e4424f3a19291650d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0a94170354505b26853cb4eeb60353d68f87010693db2750b1eca1628b12dc39
MD5 192f3fb584a94e4f0376959f9dd22dae
BLAKE2b-256 09f9c9098801df6697b98d7528dc7cd633409d8a84b1d58ef74becaee29d7edc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 84918165041c8b3f03786b3f3e05e465e12478c7313fe2b6ade231d62ff54c99
MD5 8f0b1a1da956ed6e7acd006d24c648e3
BLAKE2b-256 e09e78f3cf35f6b5e15ab3e850a1463814f85139e00270ec9faac8da0ad29048

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ee314ad527a4a492d4586a05bcf100e1ff41c08126d0d59ed81e092bd407d934
MD5 a153a50e7044d82856a574a5873481f0
BLAKE2b-256 75eac2de5aefdb518dd810555d8916c77bb78a86b6887730c51861d4eff887e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fd919ab972c9e8f351088c835b7c72884e36470cbb2d1b684139c4781da830c1
MD5 ee5b2c6031e1fc4ea38eb97d05556d05
BLAKE2b-256 4aca73b5bf2b3d91cca53d61f7ab39864c50861cee63b9eb455b7b508a57f83a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75dedd9b682df5f20415701aea2bf1bcd91778786b9f00b1f567eabfe244a6f2
MD5 00674c57355cbfefca11b99c7fa82726
BLAKE2b-256 4a3f273a464e39039245470547f1c8a7a8d5c153e3b172a6593280683943710e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ed2afd7644dc2363c6b72a7d03781ba6e7c26df45b20740e4ac3b2b93d2c66e2
MD5 7a95ef3f8d2da01b7a71fe915323ca98
BLAKE2b-256 df0ded65975ff6e2ea5bf90cd652f2eb762ebc2a731ffab95ff96653d86f027a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 26bd4409c69102c9ca25254bfe55f05128878c823609a8ab21a049c33ad6b623
MD5 d4efef12090955df888b3491285f621f
BLAKE2b-256 5728a670ae4ef1df77c721c7371f61d4b7c8f01071ab1b1a7a620b00f5521842

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5b0c7a32695423f6996f36a89a29672655d830a6a55750f38b02a9125fcbe1e
MD5 cb7ccaef9aa3ee605c2b8f622e4d1055
BLAKE2b-256 b334508db15cd40b754ca00a25056879ce1b409e295651fda4f7594f87b996ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.0-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.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1592d526e2f60be4261904ade482c913757b657cbda34da34ab4021964d1f26f
MD5 0a4a12ba3c83680c7899de6bb2df29a0
BLAKE2b-256 52990eb9065d77ed761366cff9c94156ebabad0b74ec686ae47bec1ce5ad420a

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