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.14.0.tar.gz (90.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.14.0-cp39-cp39-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.14.0-cp39-cp39-macosx_11_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

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

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.14.0-cp38-cp38-macosx_11_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

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

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.14.0-cp37-cp37m-macosx_11_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.7mmacOS 11.0+ x86-64

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

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.14.0-cp36-cp36m-macosx_11_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.6mmacOS 11.0+ x86-64

File details

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

File metadata

  • Download URL: jsonschema_rs-0.14.0.tar.gz
  • Upload date:
  • Size: 90.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0.tar.gz
Algorithm Hash digest
SHA256 d9a6903ef719438c96d78596b53c715db4aeaa836bc3e58919eabaaf143797cc
MD5 f0b2fdec6ab595790bcdcd77c48cff87
BLAKE2b-256 8ba6d1f834415e486506de7b15dbaed02828b5e42bfb1d030163c61ec9bc0714

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.14.0-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a850a2800dd776b7257bff8ac8503de74f06ac7998b7ee6f3c8732b317f10c99
MD5 8fbdef99e0bc58cc6a2d4496d1a584ea
BLAKE2b-256 fc4c2f25bb63c5436a862d7e821f6b8930cc6d20463c394118dcb11db8bc56a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad21a88f29ae4d4e5ff404bffd683b0f1790dc4df04448f0933bf83b5aeabb13
MD5 7cecc798fc938bf28470ac16a4fd82f4
BLAKE2b-256 34301f5a4b153c8c053d158037a209201e53ec6aa546d1ee5ab723d04827fdd9

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.14.0-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.14.0-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c0bada0749f68aaef1fe315907063aab4c25841a6c680c90d92287cfc25abdde
MD5 be36045c5a886fb7fc179d2df5609bd3
BLAKE2b-256 055e287ab7b3537d4abcf22998dc7975d2164171387cd5ab50d76556d7e8d427

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.14.0-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1600af49dc9d4e6b9ef87ebd488cd3ed2545ef539c3eb10dfd44ca0093d958f6
MD5 1305e8dc1ad9e0489d146e5ec0b369db
BLAKE2b-256 e17284f5d8ffcacc2517e992dd451e2b9de87a4a9c70fe6ff51311f8a31bd44f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ed623e0e257cfd59df463a723787bb07b596fbce7aa8a362650ef38b297bb62c
MD5 b5880d57787b3c2819aae1e35ad9beeb
BLAKE2b-256 aa952f4d7f337fc8264cebf3656cfb9a9f2b03561b2115ef285416abe138680e

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.14.0-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.14.0-cp38-cp38-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 3430e9abd34c7a92a4b3dcddeac0319d8c97f28079f3cb5a09448b4d5bb8bc00
MD5 54b03d6f47948ebba4dd2f65e7b766ae
BLAKE2b-256 40c290821060ae5b382038fb9ac0132e4cf9da0fb00c5d76a429f16a0108b3b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.14.0-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 a127641b1dc893b82b77bb7ee7f6ba36d4bb757fa65a37aafb746b9428fb516b
MD5 ea83cc921b25c6aa6abcf846f07709cc
BLAKE2b-256 86301de913091c782320bae5bd4291351cfd2164070e6b18efe6b26e256224a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15c7eb7a2a5dc91dd8701201650bd3bc4d5b914df8e59ee17233b027223c06e5
MD5 3207053f975f5131dd8497b5c0ff3fe3
BLAKE2b-256 ef7bfa5b2a7a15d482cc7d09a200e14a8fb0270652b1a5a460725265594abf38

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.14.0-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.14.0-cp37-cp37m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 07434e9631037afba5b42cbf83340a98f17f420f2382998e7004a1a4c00bb975
MD5 f74c0fd866a2f40d861f01d6a734c4dc
BLAKE2b-256 607d57d0f0a56feb1479e8fb0c54efa6e41a21a6c5dbb481187bce5fc0beb3c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.14.0-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.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ec892f1974e4147c3ed4ed9ab73ea37e1aba9574c0e93cab6070a5358a099732
MD5 f2e423b37f6b142853e1baebae7dcd75
BLAKE2b-256 97df0ca1fcc24585091ff2ecc5c5ec234ec2302c94f3a6541942175ca08ede1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a57bda18aefe7aa2fc8b45f4c139ee0455680a8b4f07770501951a715c05661
MD5 2c29f4e642ba90905088628d6879b35e
BLAKE2b-256 b678a860a56125ed19e8d4db8da1ecafb32719186277b726199c8a5fac1fe2fd

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.14.0-cp36-cp36m-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.14.0-cp36-cp36m-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.6m, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for jsonschema_rs-0.14.0-cp36-cp36m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ba52a2a92e40c72520ec7f2922d31d13e0a94f1252ed029cfff14dd9c5638d59
MD5 2c9a8fc06320cffcdd9277820dbe3188
BLAKE2b-256 7c2f230aeea5d3eb0e4b82c2120b843f4395cbed904abe3cbe0ac558106242bb

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