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

This version

0.8.0

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.6mWindows x86-64

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

Uploaded CPython 3.6m

jsonschema_rs-0.8.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.8.0.tar.gz.

File metadata

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

File hashes

Hashes for jsonschema_rs-0.8.0.tar.gz
Algorithm Hash digest
SHA256 9ef540b118334d270b6e979b842ded83abc35798dea6d1016aacb9573a4b3af5
MD5 78485ae8f0fc942f05314b0bd359f4a9
BLAKE2b-256 4431693be8a6ac5c521126c3fcc16d7b4b6202405f5560ee04fba1cfed7410fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8005ecf04b7900a9a86a0740ce4ad753048d8a6ab22e1c7f546978576fd55edd
MD5 b94f4b3d51b3f2af9e319aeb77c22db7
BLAKE2b-256 8ff4e81293eab8a5dea2e692a3f667fcc64fc25b47dd85e163bce65cb8ad19bd

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.8.0-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.8.0-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 671119e6ff49ffcaf5f73a9fcbeb01f4a7b9c2ec6f3f3dcf0916ba0028c30609
MD5 f5f1de598968284fccf82e0a9eb6b681
BLAKE2b-256 9adfe6971dc7df2e759e96fc362cf30de933b33961c4ee1b96af6d89749fb476

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 542c02edabf93a2d93e3ca06d2e64f71e933427118b1dd2b8f93b06fb8734c1b
MD5 cb892708b17d9def961a025a0612951b
BLAKE2b-256 7d6e0a6d46ad68a2c0fe4184c3b393ed3052336a385be2421c03e8f1e8c85c4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 05b391c87b4f122ff4370abd5056702687dc7384c26836bcd63a1d67753bdb49
MD5 536d1ebe3e2221e4e22dbf201619f793
BLAKE2b-256 649533c235fdd23bf568e9df7bfd9cb2f849b26ef651cf6176fb29738850ec0c

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.8.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.8.0-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76660c2fb2c025b64ecf5504f4bd4caa9d2fda12e316d58379e4f07c94681cc9
MD5 a2b4e1525f72bdad1634853efae4d234
BLAKE2b-256 feeed015825ed9744718648d2e1bcdd21804aadc48acd2b95d96e7aeaa87ba9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a401d6aaa9a6958197479ac7e4f50bc53060db4644344f03dbeef03b4305cf3b
MD5 a00da5f4bb5c5f2157807d95497dfbd2
BLAKE2b-256 bd4726b81bc94c38a650ba38171a16c519194c373b6615fc075955d89929151d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 8fcd5d053268fa9c5dabca6a7b88143d36e6d593b7cad0a0557dd06b640681ba
MD5 e01d02d2450acd6ee8612cfd75f77459
BLAKE2b-256 744cc785a67021b99133616f7369d96f063e7c57e8430bfc48c57966024c55f1

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.8.0-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.8.0-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 946da62cccb4f427d62cb9b565526f6918cf7cc4e5d5b22d466509b9a4790079
MD5 be59206339941c252b65300df90e8f44
BLAKE2b-256 918a8b28453f6a01cbdd953f131459b7deecfc3d979d2d3d89a4fe16f75ea99a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7b04fe21167be88a74ff860bd552b49a9124146556f58bccd9b4ea2a1ebce652
MD5 c4fd7b03f76f011663c2a6e46d6fbfdc
BLAKE2b-256 c98c9f4fe33dcaa15a70dbb3f0a016eef038a6b444c8bb3b7513bb043a70f699

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 e46ba932d9c981bf4bed56023815ba4bba835f54da79d68019ad339c62ef1d82
MD5 a81657751889db4a628ab14827b44003
BLAKE2b-256 f5a545de9e59bfe6e8099f5cb3a004183d72e43a8d1a03739c0167e6c365086b

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.8.0-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.8.0-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f67de67ef12685ce6a25d34f0d8c0806914a23145e360641d42aa2abfeec5593
MD5 8226d42fb62b6e79d6cd423e2a754a7f
BLAKE2b-256 b410199fd3dfb64c555991b690d3bcc202f53c3612406c1f58fa7aab9cd15830

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.8.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.8.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 45b579910633a8a9ea26977fd5661c88c690049b27f4b19bb2b14bcbeb6a6bd6
MD5 6fd1b14f6d5a90b22d8d2897ec4af196
BLAKE2b-256 ea1dd19eea3761cda27858e0fdeba549062bba8973b66b6086fc77dd982aaf43

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