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]

200.82 ns

203.10 ns

1.22 us

1.51 us

jsonschema-rs[is_valid]

187.60 ns (x0.93)

185.24 ns (x0.91)

850.25 ns (x0.69)

1.18 us (x0.78)

jsonschema-rs[overhead]

180.83 ns (x0.90)

181.68 ns (x0.89)

638.40 ns (x0.52)

1.06 us (x0.70)

fastjsonschema[CPython]

58.57 ns (x0.29)

109.10 ns (x0.53)

4.16 us (x3.40)

4.75 us (x3.14)

fastjsonschema[PyPy]

1.32 ns (x0.006)

33.39 ns (x0.16)

890 ns (x0.72)

875 ns (x0.58)

jsonschema[CPython]

226.48 ns (x1.12)

1.88 us (x9.25)

56.58 us (x46.37)

57.31 us (x37.95)

jsonschema[PyPy]

41.18 ns (x0.20)

224.94 ns (x1.10)

23.40 us (x19.18)

22.78 us (x15.08)

Large schemas:

library

Zuora (OpenAPI)

Kubernetes (Swagger)

Canada (GeoJSON)

CITM catalog

jsonschema-rs[validate]

13.970 ms

13.076 ms

4.428 ms

4.715 ms

jsonschema-rs[is_valid]

13.664 ms (x0.97)

11.506 ms (x0.87)

4.422 ms (x0.99)

3.134 ms (x0.66)

jsonschema-rs[overhead]

12.206 ms (x0.87)

8.116 ms (x0.62)

3.666 ms (x0.82)

2.648 ms (x0.56)

fastjsonschema[CPython]

– (1)

87.020 ms (x6.65)

31.705 ms (x7.16)

11.715 ms (x2.48)

fastjsonschema[PyPy]

– (1)

38.586 ms (x2.95)

8.417 ms (x1.90)

4.789 ms (x1.01)

jsonschema[CPython]

749.615 ms (x53.65)

1.032 s (x78.92)

1.286 s (x290.42)

112.510 ms (x23.86)

jsonschema[PyPy]

611.056 ms (x43.74)

592.584 ms (x45.31)

530.567 ms (x119.82)

28.619 ms (x6.06)

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

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.11.0-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.11.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.11.0-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.11.0-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.11.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.11.0.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.11.0.tar.gz
  • Upload date:
  • Size: 67.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0.tar.gz
Algorithm Hash digest
SHA256 5bc1f2a82d5a0cd6bf942c1e81b87802d8e43e3b8f5b5605f7a026668da32a2c
MD5 332ffb2e5f88994af1fed3ac8336f93c
BLAKE2b-256 821af65f769502c1a501b835ae086bc202fda491e6160a7dbafc2be803c29582

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 44431c3502a69f6fdc649c9e01969a16702ca06f1e2f219e568279bd1768f747
MD5 bc04e9e0067ea3146c3fa436c6fefa98
BLAKE2b-256 7bcf0436b19aed9aeece53620efc7275e06af86aa981dd6036ed4f642811eec2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f61455d23e4494e4319707d6bd428d01d37d135b374573294cc9e43129e06ba7
MD5 c4aed4a4ff54cd4dc2a22a6f52ddcfcc
BLAKE2b-256 c2a9c7c0c7da6abf15f3ec9b80dfe3063bc0ec8beb2c64b26b039dcb33ac245c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4ade0a949c91831fef0e897c338faa1193ce7784e9b701d60729184d97ec66cb
MD5 9f6cb8356d8f00663da1aad70ae3c649
BLAKE2b-256 671adb74afc14abc0ff3ab32e7e5aaa45709f06b25f1adbc78d495f2cf6bb4e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6e4590b544e613eace35681e5abc073e113864100efe03021f56cc8a79bef1c3
MD5 a6d0cf4a6ca700a388a55dbeca4465eb
BLAKE2b-256 81523a29722ff9fd9ccb8c2e0b139ae6d637de40e588f2097160909f181d8418

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4c3011ee418b84924a962428f431e79cfb1b59940646f89055e65b0b9652111
MD5 64bf4a7beaf27d9b2bb630e74ddacbfa
BLAKE2b-256 0f5d8526973d655817da30e71b362be410d0edccc3ca87d58a1f1075e5505e9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c862bb396cc85b0467271a8696dd324c74eb1a34bf8ce9fa9c3ebce3b25a0365
MD5 a0515facc51e6814c9689d6aa055f7fb
BLAKE2b-256 32ab77d237f66d5a59a87a91953200d5d2e04744838c8e0d92e81b407388ea06

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 88efc05c950894045df7eafce12c5acab13048786e0bb9270c6d570f545dac8f
MD5 d6c02f88a33d075dda16d796d02260d6
BLAKE2b-256 72729cdce3c0aa698c35d559b0517c229ddff4fb0627178026ec24a627eba233

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f96f2aad5226729f4d91043df23946e13f341260728af6024242329e41fb64c
MD5 07331c7f63719587646c6cd93c65b090
BLAKE2b-256 86a9d36736eaf63d653eb7a04c8991895d3ee4db98fe636e3bf8585be9575b02

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 90802884c297d64fefc48c0c3a200aa8f4191b3b49ad5b857e3eef5fe5e40775
MD5 35bec3dde5dff3d4a9f52742541a7b3e
BLAKE2b-256 50cd8726dc2d8ee891af9e63179e8d131f03de67328648b49663614db9a7d0e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 637701c428ba2ed9df1ceb821c8a70cb60d55a1d0e3f3a3cd8be8884d96b51a7
MD5 57f17e4d517870cdbbbd04094302c2c8
BLAKE2b-256 bdb605f0a1669b7cdf60967014e1ef26ad6668edd2591baa1715f7ef47b36adc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fae3b8887f84edf040e839cf3f2a8347ab956c0ff9afb4c05541d9bdbf86d1d3
MD5 cdb598524e47015544c3f21e0b540fd3
BLAKE2b-256 7c78a8f4e7da42681ece62c5e54d2209910053bc6994bf233e1f6b8eed27f2c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.11.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.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.11.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 de0e6535f30473a9d8b4423a96859b4ab12e27729474ed90695ace15a9211709
MD5 8be232c2a1744f360e0de3b88e337f52
BLAKE2b-256 15ff7137496c06013b4a2a38711e46151655f87e07febe221ae20e1f5599c5ac

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