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

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.12.3-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.12.3-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.3-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.7mWindows x86-64

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

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.12.3-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.12.3-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.3.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.12.3.tar.gz
  • Upload date:
  • Size: 68.1 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.3.tar.gz
Algorithm Hash digest
SHA256 e82b7c8824161e7ced0171c85a1a98b837eba47667443994e8730c8d1a46db8f
MD5 608cf99e89fb06b7e966fc4c30d1e848
BLAKE2b-256 fe0b97d28e08d86146297642f870f5eb258404b72b450fb0f24a4f0816fb4da9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 058d5c5766144f098820dda6f378c147c2114dcc5900bdc2c29225ca45d0953b
MD5 1cab0b8e049b4b7b8879360dfc162220
BLAKE2b-256 5d81e8f419b313fce4be2d297278bfc598a3438782e6867d7c6f4da601136602

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4d22ae55a9a1f1a0c64a3bd136d23aafb1f206c4330f28b2bba5216542170b5
MD5 bf8399b5d88272c240adf7520053f454
BLAKE2b-256 84b649969a437a1f3e88a108aeaa8900b8dd0aeecc07de4553d35a764dd0e2ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0aca16150eede373d4bd25a885b5bce1d9e4b7fc417461ae6bb87eddd00314fc
MD5 1a9b871f160acae3c176c5128448db6d
BLAKE2b-256 f769f5185e8057be247d844329baf05cdedc12ffc95a13d09e59761ac085f30d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d882478b5f30afd7e8e8bf7064039ad7551eab1a1831580ee611b683f363f70b
MD5 0cb453664109a8bbef426ac9260eade8
BLAKE2b-256 2222454e15b2fb185d304e77e0a806357a221d5a41cf8e3db45dd79c6a527f14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af5ef407f09365758d2a8201442ebb0e59da128cf898aecf53af5a1223da3c08
MD5 0866c668175cec8c177fb5cbb8c58814
BLAKE2b-256 9f1ec5a6c2001bb5d435e0604173d1bb97a9f06144e9d734145ed6e47821fa82

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 268d8f0dca5817490f3d2e2b262c31f8c115eeb8a5281a08cea9623f6d49f020
MD5 fb48fcdbb7b6f6688e5b069411bfaaa9
BLAKE2b-256 a088bf5f0bacff738adc80f996c6e2336fc17dc69404d8907bdfa39c5d74a5e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 37faf28528180abd1f650b12ab38ebd9cebf6137bc8da71493c3305d351b9e85
MD5 9482fbf74277e0fafdae254109bf8336
BLAKE2b-256 6a7e5f8a1c64b8c615c2d7e583f8701f6c55c3fd76345403e2f2c80a0f2851c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c23c70cbb2c811129d5d11c8b30b75f514f00562935f39eec79a6aa2b74bb38
MD5 c736dc0121d2fea7431492ef8839a9b4
BLAKE2b-256 6a31321a480a59162f7690bd68fbd74ecbb30c5295a030e78dc03fb99624dbc0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 736f5db928af1ab3b93b413f3a84955bf3fe8d88061e4b03e76ca64b5396a9b6
MD5 600bd8ca831c06b65cc54f05751b78ed
BLAKE2b-256 0a1b1576aa69749966291a1402b34506e0870aba57b1aaf0274d37dce63c10bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 03daf03ccf65eeb176393828c0f7e9c7388273de60004b08dcf35992ea518445
MD5 f5e12099a4540160355487aff8883ce4
BLAKE2b-256 838c8d651c8bbee3fc10c7703a5b2f4cc8720ab20fbfd360ac11c33af45149b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.12.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe31f6ed39f57858e3d8e6da0629e91fab329a02aaec9a5197c2729945609b14
MD5 996152aa2f3fe2e2a157749384a05d27
BLAKE2b-256 f87c793385938ffce672254eedc6c708d505a55d8383eb6c794eada0ec3c07b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.12.3-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.3-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d2bd70a6895802e1dec6f870ed5337b7ca6ed843bfee8cc4775f12c617a19552
MD5 7ce419d59d161638fd5b44512c676a9b
BLAKE2b-256 365248181b01a1623a62f47ff58d9645eb2a4c017dd399d70fab791ca4f52846

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