Fast JSON Schema validation for Python implemented in Rust
Project description
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 single-keyword or boolean schemas it might be slower than fastjsonschema or jsonschema on PyPy.
Schemas:
kubernetes-openapi is an Open API schema for Kubernetes which is ~3.15 MB JSON file.
small is taken from fastjsonschema benchmarks.
Compiled validators (when the input schema is compiled once and reused later). jsonschema-rs comes in two variants in the table 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.
Ratios are given against the validate variant.
library |
false |
{"minimum": 10} |
small |
kubernetes-openapi |
---|---|---|---|---|
jsonschema-rs[validate] |
200.51 ns |
203.30 ns |
1.09 us |
14.97 ms |
jsonschema-rs[is_valid] |
186.00 ns (x0.92) |
186.79 ns (x0.91) |
884.40 ns (x0.81) |
13.94 ms (x0.93) |
fastjsonschema[CPython] |
58.57 ns (x0.29) |
109.10 ns (x0.53) |
4.21 us (x3.86) |
91.79 ms (x6.13) |
fastjsonschema[PyPy] |
1.32 ns (x0.006) |
33.39 ns (x0.16) |
1.17 us (x1.07) |
44.27 ms (x2.95) |
jsonschema[CPython] |
226.48 ns (x1.12) |
1.88 us (x9.24) |
58.14 us (x53.33) |
1.07 s (x71.47) |
jsonschema[PyPy] |
41.18 ns (x0.20) |
224.94 ns (x1.10) |
25.97 us (x23.82) |
663.30 ms (x44.30) |
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.14.5
Measured with stable Rust 1.49, CPython 3.9.1 / PyPy3 7.3.3 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
Built Distributions
Hashes for jsonschema_rs-0.6.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6190bc459bc938a06c0579d4ee16bb51bd3295fda8ff3074550d66dfbabdd21 |
|
MD5 | 9db0fafe3f9fd5202f7e01c99721f2a8 |
|
BLAKE2b-256 | 8bc9acd336fa9faf09918d85428e67ef460a5bce3e1d824dbc2b1eb8013d2400 |
Hashes for jsonschema_rs-0.6.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a798ddfdd7ad971f74f20c72bc49ccb869ceaf5b580458597226c75bb87b1e1c |
|
MD5 | 9a498d43b0e24075911bd55a3268b08c |
|
BLAKE2b-256 | bd8d206916c37c0901eec6b8435bcf91dd0080a42b5d651f2f584a29889d1bd3 |
Hashes for jsonschema_rs-0.6.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eec8ddd673e469f09b11859f5c0480f9ddf2756d562a3466e8f2f2d977ba7883 |
|
MD5 | 4eef89a6254a9192e8151a690c38d566 |
|
BLAKE2b-256 | de17f9568f4a3b2695b95ee5535c5cf32a256fb34b9e0fdea0c701c102b9afba |
Hashes for jsonschema_rs-0.6.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc291cf3b1b294de3c95f709ab5e62ab227f1658e8ac9fb2e0f5c8777361fad6 |
|
MD5 | 907b723208b76d5a54f20bd48533f4c5 |
|
BLAKE2b-256 | 88f0d130fc5dfa5962b19e93515451e3cd7d34bab33461290e31926daad7bc1b |
Hashes for jsonschema_rs-0.6.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 053c311d383e14b8820260e6dd005812e4c2406ba01d54cd99de77eb1ded4245 |
|
MD5 | 512cbabc7faed831856dea8a79dd334a |
|
BLAKE2b-256 | b5c72c5e8499c3d29d2853f9814c983efc1d1b3697bc254284e3514366ac53d4 |
Hashes for jsonschema_rs-0.6.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e218266111cc3dbc4acbc179844b51818811a53af5e3711c68957bdb726fcd91 |
|
MD5 | 7c8f9983f2645f29fdda88a634bfc3d8 |
|
BLAKE2b-256 | 86c7ff225bd3ce2759596337c1bb75bf311f5afc755fe898c01c3daf7787af67 |
Hashes for jsonschema_rs-0.6.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 015cb8305a5105d2cc57a0dc0fd4afe5fc6edd31abd5dec5988931e0a35fe30f |
|
MD5 | d5693223bef5f7b709e369f7cbbf9810 |
|
BLAKE2b-256 | ab06c7408f0b5dac937382076261a3e31d7a0700526eb864a51a821c0f9e6a42 |
Hashes for jsonschema_rs-0.6.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3610877ccd63a64fccccdd98261e9cafd654f239bd5c000fddcc011a36c57f6 |
|
MD5 | 02b33094b6f12dcfedf26cc38f689f67 |
|
BLAKE2b-256 | 1d6e78f1fcf2af876986af636f51476179220813fded42369a7eb69e5a3dcac2 |
Hashes for jsonschema_rs-0.6.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67517464bb308a2e7d2aecf5afd74ad50b5050529dc15a88aa27dc6ee0d7d255 |
|
MD5 | 3d3eb73dcce673676278732f85a8d911 |
|
BLAKE2b-256 | 38c660821e42d3bcdbac3163c64ed5aa9653a323a40f1a79bd398473738274d1 |
Hashes for jsonschema_rs-0.6.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1284811e30333e1944f6abd52473f77bddaae50c1ddc7cbd105ca6dc82a4d127 |
|
MD5 | 148889bd3a70127df89cd976c33e3a11 |
|
BLAKE2b-256 | 5924997012a76b9fc8bb78f5759d0efab5e9da78be3a0420bc42730f8dc80d21 |
Hashes for jsonschema_rs-0.6.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b75129a41c9f81cceed0e8c77db4a65a76aa456efdd37d2512f3554e8d1da8c |
|
MD5 | 39798424f5d6341773dbe53cb9742da0 |
|
BLAKE2b-256 | d87203886000b556c67bdd6402ee4958163643758e9730b53f37ffc4456a905a |
Hashes for jsonschema_rs-0.6.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34decd8df4b00b79e448d06496eed3ba5b4d7d7dbb83a0f3938590d2cf242855 |
|
MD5 | cd559477f14cd87c6dece3ec87ef6a3f |
|
BLAKE2b-256 | 9372d3932cca78a0473c9423a1ddd3611e4ac8c68a160348a4899d337b1c25e5 |