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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.11.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.11.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.11.1.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.11.1.tar.gz
  • Upload date:
  • Size: 68.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for jsonschema_rs-0.11.1.tar.gz
Algorithm Hash digest
SHA256 c68e91e405106cf277414c8d34198c605d65224edf1585bbec1303180d6678c2
MD5 f09fc9f914028c42db182b2485dffcdd
BLAKE2b-256 cb98caabf55714d9afeac0df362a98c6e84a12324bb1894bbc04aebf8d8bbfca

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c4c1724f95b48746a28a961b47330a3fe798cb23bd9f5d346aa445efd8983de7
MD5 852acf78aac35092c074258ca985c65f
BLAKE2b-256 fc6ca135d5af9cd6d8b4696fff55d323779c559fd0eefd3e85918b9541b84d18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9c1ccd4488944e292dab4e6d95d9ab2f59f240444d4980736ac65fb25e6c52c
MD5 a47251a10d58ca66cc17ea2e4a30081a
BLAKE2b-256 2802756b79d71311a7b0c48d009e8bb6c5e44f94426fd267e0cb6c1ba1c937fa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 738c9a68045a340c6a87cbf41e9e9ea07f6aebcbf52791dfc510f69f710de86c
MD5 4eb5ccdfac2d3d398fd55a1f66ee1133
BLAKE2b-256 31d76f1243dd4d6bd3240f4038390cea6fd57096bb1f7a0487cac76e05adc983

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 06cf574ca06bd936aa023adfa935cbe37e7b870a048e90a8d2aa95dbd9bb24f5
MD5 3e26d46427a55d3329ac16661c5ae0f3
BLAKE2b-256 53b52413745af5ca6f7fe86efb496868939fd2f924ad99762862e449d8cb4d07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 653f4dbff1ecb6475af24459bf9ce89ba78c2020343829d13d92fcb705575efa
MD5 2bfef502661fb6ccd99816d724855cdb
BLAKE2b-256 d45aeb63d1d63162769e6b0efe0132935d77cb6c0887336fa062149014d902b8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 94d17686069014840dc748f8189816e4350f108cc2a43c2ea91835d09d645d9f
MD5 914f471f5462e9b337b8b4715bb0a1e1
BLAKE2b-256 05df2ed0b7cb87985f7b68c6e8d18c5b4f94cf07511409698b8128edf7ebc1d8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ec7db014a6aa512dc2616f55144881546f7063c1ed564aa076bd3b95bd39aea2
MD5 4ae7a073f2d73ed97196453db6e87abb
BLAKE2b-256 f57e0286821410edd6f68c1b410a7953cefcee3aab8659d166b5d4c65e22796e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d4ec6b90287c1a937803e1f7b5caf6dcd64ff3118fabd9a4fae1520c7641af6
MD5 4388a895e666589bf876c1f156399ec3
BLAKE2b-256 ca125fb696885310afe4cea3fa9c32d99c5ac74ffafd1b6a873a2d217be0876b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d1480a5a8c7c20b7ef1dd026ad01a39d20199b8864cc08b14fac606917ad3d54
MD5 3ea6dd2615b3f3459e8633f1507575cd
BLAKE2b-256 c824cd6e249907531744bcda287daad5832aa6a7c9270d0aa19b0549eb9511f2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5696dde504c0e0c6b7286333b9bfb83ae7ee8e65ca1a0f093a7a7bfa4f13b52d
MD5 d33f204d0144af762c2835aa715f366a
BLAKE2b-256 aa2d03440b9db8eb75bf0468a0762d1ab76e7a81f71fd68d9ddfb915dc81a897

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.11.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4bf21c10e3b436a714d07e76c910c96ff18f65eb7bccde215057801a0c47e3b
MD5 1eb6a71b055b74c93d792cccfd369819
BLAKE2b-256 b4b2545b4f8e7b08f90a52e69a94795a288e4986dcca559ff24e4c5c999c1be9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jsonschema_rs-0.11.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b5b4ffbb151ba0c90a6a2044949d50049c8833399e68d3d06f30934743c39c44
MD5 72f0f1f321efc6d9036239eb04810f6b
BLAKE2b-256 621db4322bf4b14daeb0871817863d09b75c2a097986aa090ceac5eb7ff6478c

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