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]

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

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.13.0-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.0-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.0-cp38-cp38-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.13.0-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.0-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.0-cp37-cp37m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.13.0-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.0-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.0-cp36-cp36m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.13.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.13.0.tar.gz
  • Upload date:
  • Size: 88.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 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.13.0.tar.gz
Algorithm Hash digest
SHA256 43c45bb4b091dc1c783801437172f41323b109db99502304656ec7f6db3dc170
MD5 56ea0bd44ba75cf0463397fe86ff9d09
BLAKE2b-256 b5a2cbbee22879f9db01e4cafd4779fbc493734a85c2c80738006eeece1c6070

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.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.5.0 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.13.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0b23d7f7f0439e9ad59905b8de5f1a97d1d5a155e467e568fbf28173543b1049
MD5 e39eccf064e0e5dc8bddeace25ce4624
BLAKE2b-256 bd885c697aee591e16dc884093726e02d38349915c8a340bcf15033e55528927

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01f3926e49c6be1029fdb4428db1b03ca48d9adcf6c5ca861a9f1db9c0201c29
MD5 3de6cf6ac7f5a33bf86c9639e998a9e8
BLAKE2b-256 1a71e34790c6be87e19f125f08f17111f884c2b35c8ec843b1dacf2106e4c92f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.0-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.5.0 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.13.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 93d0fe300e5f3080961a3989bb62320da46d3c610897ad4a1571a519af53e6bc
MD5 0eb071caf35ae44f41103de0154e817b
BLAKE2b-256 2af5ed9f7b7a4746117965874dd9198eca8a5dd2171db93e568f13b9a0b54d04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.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.5.0 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.13.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 deb90f2201ded58572c4f72b732f80ab1010af453f1f6a3068b8598e4b03dd05
MD5 234c89618534025f43afaa3bd0c77ac3
BLAKE2b-256 2625cfc7c2e64dc04b5d48c71d1fc8f24e1fceb254f2291c15ae48494ce09d6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7de3034c0011470e78c05e3c6adaf18ad55c2e3333ee9f9057be317ae1b4b29
MD5 591308f2aa5a7f83ad80e98a03c944b1
BLAKE2b-256 c7571523997afb1d250f0b6c33051634872510b44223d56002c77aa7e3407129

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.0-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.5.0 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.13.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a2b2c797bfb0c4ef66b1c2d13b881697e234996f457b6cc9bbbc5d4f7bdd0ebf
MD5 45fa19d3f7cfe800bc48c55253af60ed
BLAKE2b-256 f1d421d7b4503e73881eb02f78c2b4aa8384a352fd7471b0ddb9b00e30e77745

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.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.5.0 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.13.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b4aaabbf4bc52fc9f2dc00d6d38d7262c0c2507d5d91b213280ddde48ac1f395
MD5 e0cb1b4f947835e68bb53fc2f8e89a66
BLAKE2b-256 5460969aa9823b3c7a181fe9dc6f4523284c7ce737afff0e8d1b097c597f9c24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c183077e524e39bd8589187c52cbb40c7f585cadfcd492f9265d61f56762613
MD5 82debe266500befa6f285525485f2c31
BLAKE2b-256 f67073bda96d2f3a10a95c34ec920adbfa5a4959997cb9a538433158e26a19e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.0-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.5.0 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.13.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7089e0c6c593b6f64bb2bd0e98732a25f01586303ddf1ed352dfc1f4418a5128
MD5 45266884e88130f3cc0f59899b5b5e72
BLAKE2b-256 f789dc43ea5e3aa3b5f8fd0df2987055b242d91cd937d0dee0e959906b07436f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.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.5.0 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.13.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 e9b0987efe852683834fda1ffdd9b971052ed53a7f02213f7d02fd208855af44
MD5 1298ddd5db5157b55de9a3d2dd616d87
BLAKE2b-256 ba643a505912473127fe47c2045acc3f3891612ca688fb14cfc7c13e5b2164db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.13.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07e80c1cd32ea63c27f6e03e99bf78bea5f7bff8d6297d5ece79de3db49040f1
MD5 c7fbb243d251caf7606998be3b089a7a
BLAKE2b-256 8a861979aa11cd73fa3c9f17919a916583d04eb48b159159c21b410e47d30082

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.13.0-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.5.0 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.13.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 77021f378b84ea68728e40a425f874b8f24ad0936e0667de148e713e1945ea72
MD5 7d445d226985748347fbdf30f37789dd
BLAKE2b-256 5fe4d3aeafbb0ed81abeb5d7f7d1464f1fb4240d0968d3743c41128ec594bfcc

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