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;

  • Unicode surrogates are not supported;

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

If you have a schema as a JSON string, then you could use jsonschema_rs.JSONSchema.from_str to avoid parsing on the Python side:

import jsonschema_rs

validator = jsonschema_rs.JSONSchema.from_str('{"minimum": 42}')
...

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]

93.84 ns

94.83 ns

1.2 us

1.84 us

jsonschema-rs[is_valid]

70.22 ns (x0.74)

68.26 ns (x0.71)

688.70 ns (x0.57)

1.26 us (x0.68)

jsonschema-rs[overhead]

65.27 ns (x0.69)

66.90 ns (x0.70)

461.53 ns (x0.38)

925.16 ns (x0.50)

fastjsonschema[CPython]

58.19 ns (x0.62)

105.77 ns (x1.11)

3.98 us (x3.31)

4.57 us (x2.48)

fastjsonschema[PyPy]

10.39 ns (x0.11)

34.96 ns (x0.36)

866 ns (x0.72)

916 ns (x0.49)

jsonschema[CPython]

235.06 ns (x2.50)

1.86 us (x19.6)

56.26 us (x46.88)

59.39 us (x32.27)

jsonschema[PyPy]

40.83 ns (x0.43)

232.41 ns (x2.45)

21.82 us (x18.18)

22.23 us (x12.08)

Large schemas:

library

Zuora (OpenAPI)

Kubernetes (Swagger)

Canada (GeoJSON)

CITM catalog

jsonschema-rs[validate]

17.311 ms

15.194 ms

5.018 ms

4.765 ms

jsonschema-rs[is_valid]

16.605 ms (x0.95)

12.610 ms (x0.82)

4.954 ms (x0.98)

2.792 ms (x0.58)

jsonschema-rs[overhead]

12.017 ms (x0.69)

8.005 ms (x0.52)

3.702 ms (x0.73)

2.303 ms (x0.48)

fastjsonschema[CPython]

– (1)

90.305 ms (x5.94)

32.389 ms (6.45)

12.020 ms (x2.52)

fastjsonschema[PyPy]

– (1)

37.204 ms (x2.44)

8.450 ms (x1.68)

4.888 ms (x1.02)

jsonschema[CPython]

764.172 ms (x44.14)

1.063 s (x69.96)

1.301 s (x259.26)

115.362 ms (x24.21)

jsonschema[PyPy]

604.557 ms (x34.92)

619.744 ms (x40.78)

524.275 ms (x104.47)

25.275 ms (x5.30)

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.1

Measured with stable Rust 1.56, CPython 3.9.7 / PyPy3 7.3.6 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.13.1.tar.gz (88.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.13.1-cp39-cp39-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.13.1-cp39-cp39-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

jsonschema_rs-0.13.1-cp38-cp38-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.13.1-cp38-cp38-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

jsonschema_rs-0.13.1-cp37-cp37m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.13.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.13.1-cp37-cp37m-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

jsonschema_rs-0.13.1-cp36-cp36m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.13.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.13.1-cp36-cp36m-macosx_10_15_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

File details

Details for the file jsonschema_rs-0.13.1.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.13.1.tar.gz
  • Upload date:
  • Size: 88.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1.tar.gz
Algorithm Hash digest
SHA256 1c8e7f1a3df555d06fab4a2e1ef8e09bf730c554d11e1f5f3a7bbf390969a30d
MD5 8822832c97b6b2d52539adad7ffd9d7a
BLAKE2b-256 807324f36d4d09b66262f15343ed15e0e9e1d1d2fadf79e94760e8b4025ee5ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2b50ee23d978a0b47ec02a338fb86d2408af8eaed467c5cee996d6fdb56d8a21
MD5 5e494d5c98374ca62b6ffd7e778d2155
BLAKE2b-256 c92854caa2e50b99b0990ced645bd2f00732bf916db49b890f1b5eb0e35168c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee1335319a291607b63f51d56d9e7fbc602a86cf0e1b361cc22661ac56edce0a
MD5 94cf0166fd64aff561ee8d8f32de63f5
BLAKE2b-256 9db606ae399e0d9f54530cc3d8fb64b999bd77172cbbf200bf276495ed097a0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d770746ad92a548c07bea58c195eecb4b20ef9fba7a81c8fa45d8ac084af606d
MD5 f55330be4b553b563ea976111e28a7ad
BLAKE2b-256 74ea2f527b91178f24f8e335f2aca690c32ea6ad634d5b13bd3a17d577f54a7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 86731f8102aeb0dbaa4423dafc0aaa4928f1857fb61c38e090a31154c4077e66
MD5 8eee44d23847fc5848292171f81f0109
BLAKE2b-256 14513a9d7c409214af7ab947e195ce68b41406214a36773aacd4265c8bb71ff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76580276aece055fa719338b2a7881e96ff845e1ae5ef5667bbfa4f7ece532ba
MD5 1943c25d07108821ec1bbf76444137ae
BLAKE2b-256 b9bd954fdcbb2f8433334dc514be0c63423c083515479e2efd042673df0c834a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c69eac35092e5418ee2708b15f6ca91417187eca151d3e39f6abe3770bfe1ecc
MD5 91be321cd6d0fa8eec8f672f422c49ee
BLAKE2b-256 68b4f65f79c5469baa57aff1c1b2920cfe036873e063e92ce41773569271da0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ed69f6799ccbed169ba21521e1a71da0465e1280418024e824bf6950105f0ebf
MD5 4da0290cb65ce56b1570a639c3c2cdaa
BLAKE2b-256 6a91250f271fe92ca91b6b9451dbe68b29d8e9c2a804ecf73412ec15946ebd75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9fe48ec2deb83a12d9561aea259783e5775521cb2c19a1796e054df5f42c1136
MD5 5877dfffab1e9bc604cc93a4705c5842
BLAKE2b-256 ab1b0052fa6de9065b5167cf50c99e5cd1af86c569145cf9ce95c6a1b40f507f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e25ba6d69c2df0ea0cc0d9c8e795cac2180a432915fdaf2c25de2a752d68be61
MD5 bd261cf07df266ca565e96c6a6c4fd83
BLAKE2b-256 3ec9daf9d1dea8478ba10c45e3f6b5d18ee3314efbcf80525186e9f02519d5e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 bc73b5ee3872ba415ff8178bb2d55cdc2e534c3f168dcb6d425173a81e71c97b
MD5 5dfbd1902bdcd443cb28c0c68dac6e68
BLAKE2b-256 3aa784aff79a2de9001341ba3dfad1c7e903d12666294cc7bc803f021560cdd0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f142afa5925587e684abe392fb5b19566aeb16424a2ee6b99d40b3539186a8f
MD5 259665703b474b8f36a4fa503e419cdd
BLAKE2b-256 a5756329986c0119815c675183aa48081f4c96cdb0db3817d6bdad5d1630d40e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.1-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 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.13.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5bb8d47655813df5daa5248121fb5d5e85590f6732b1ae9d7b031befbc1eb7fc
MD5 77be007ea9a00db7cd0e3472e96e1601
BLAKE2b-256 73450ec0d1fd6095070fcffd74d07d49baf90c6ec740b0a8928f78df68de814a

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