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

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.12.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.12.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.12.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.12.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.12.2-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.2.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.12.2.tar.gz
  • Upload date:
  • Size: 67.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2.tar.gz
Algorithm Hash digest
SHA256 29a2a2705e852cc6bda1e49326575d13ddb2708d2e711a900a9ca4f1d741a91f
MD5 42b88a4c775d2c27d0d142fc2255fa10
BLAKE2b-256 76b1bb57a78c5e49bd57ae093d0fefdbee7a8e39e63e66954bc9c5bee2f44a3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ff72b71e7fce2466bab23b11781027a917a78ec73c3b9f543326dd6bc0de7d29
MD5 c840bc87a2275ddb86b65aba92f07bd0
BLAKE2b-256 e80694368f152e6104e6f4405fb73c676b7bc2934febf1e39dc9947d5fec6c77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b6137883724305d63d020a80ba18e3889f7facc32f24fd22c13b35455c64a28
MD5 dd274e789faf16b2a00df30913e5a4d2
BLAKE2b-256 3b3bd18a973d18f4d5f8be506b737ea5d5baa4d50c413ddb79f462268c14bcfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3c590c196c166f100c6065757530982aa05ad1ed5de264f7b18384a91252d400
MD5 9c199783b99d0adb8b1a39b196204672
BLAKE2b-256 8ab7e0525fe19235d6d1602d474cda317eff3c318b82ee282b623b56fe500b14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 16fb58db3468c689c6fb378623efc6abd6bb60ac35ec3978849a791b95106293
MD5 f2bc551d49b1e1d9718f825edec17a79
BLAKE2b-256 fc9d4a61edfa277435ec5e1adf0d6df1b85e646626ffb02e63310c1b545e2aec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90dc8f18571f863e81a9085fac40e0b5c6dfb4473fe97a09ce501662a647efac
MD5 59f53c41484472f2c20995afb28e24e4
BLAKE2b-256 535cce15e37ec31271c8817abb38cfad313518dc845128f325271d0bdc13cb90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 afd472807997786121184cd299bbc609a241917fcd1262a05d6b5614091454a9
MD5 7f0b55df573a2bfeb1e3f8f064c4a342
BLAKE2b-256 974c84251912ad1a7ee9a8eab5a3814fea61bd48e1aa56e2f2ecd3ce35f4b711

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4e46c45f54a36f40820d0b5ca25c600c9888f458065c340f8a40df2183bcca99
MD5 94ab6b0856e5fb1dd7dad33071679017
BLAKE2b-256 3b43cc934e8a6626e105ea0654ae331241e15c124c1e1441e4c27f8829bdd66f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92698a2757a1716a67775110801fcb10cd65ef735d18d93aec83ac3e33f27052
MD5 72f67086cf0a79452ff88c3bd46139b0
BLAKE2b-256 eb5ca6c1ebc873487eb3a98e9fa161202ff43c62d29403a4d9e57e6e83b418b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6e5c28e2b2c5ea2bbeeed31af6cbee3690ae4b5e957d0cfbeb6cb375d0197346
MD5 1b8fcc3822e62b5a308272fb94e24e27
BLAKE2b-256 3e4c98b7e5e3dda8caabc51531339ce692a046c5ff2eeaa4f5a5a9b7a14cff68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 988aeab9a54deddaeae17360326e11f4662faa3e99766b0028b1ae8c01ca4ad8
MD5 4144f3bec842d1a89037560febb003e3
BLAKE2b-256 e0b97307229338951e254e1964113fcace4418ed894ada2a71fd9d6966f6d650

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 10a4f387108f55939664cc7133839949f8b4fe1fac41caf954ef38a1db5bc5ee
MD5 507d6f2158b40369b031c4767a3cd6ca
BLAKE2b-256 a3bf8af1131f5b38d4f8dd90bd7921bfb8479ca02e4545cfbc2bd73dd2bdc481

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.2-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.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.12.2-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ab893cf3eef618fcaf87c188124f6f5c4951956b014f0caa39546a4fd55e8be0
MD5 09ba1f1e6e96c9be7b80d2b1d5e17a3d
BLAKE2b-256 db5740628be735084f2ad4c404f2c4a6135a4afa924608fc6d1892592538597f

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