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.
Compiled validators (when the input schema is compiled once and reused later)
library |
false |
{"minimum": 10} |
small |
big |
---|---|---|---|---|
jsonschema-rs |
141.45 ns |
144.66 ns |
652.84 ns |
4.89 ms |
fastjsonschema |
48.92 ns (x0.34) |
95.22 ns (x0.65) |
3.91 us (x6) |
554.74 ms (x113.44) |
jsonschema |
204.94 ns (x1.44) |
1.52 us (10.54) |
57.44 us (x88) |
1.38 s (x282.41) |
Validators are not compiled (jsonschema) or compiled on every validation:
library |
false |
{"minimum": 10} |
small |
big |
---|---|---|---|---|
jsonschema-rs |
328.86 ns |
448.03 ns |
6.39 us |
4.89 ms |
fastjsonschema |
55.29 us (x168.07) |
106.01 us (x236.6) |
1.3 ms (x204.53) |
557.35 ms (x113.97) |
jsonschema |
45.95 us (x139.69) |
54.68 us (x122.06) |
758.8 us (x118.74) |
1.43 s (x292.43) |
The bigger the input is the bigger is performance win.
In the examples below, big and small schemas refer to more realistic schemas and input instances. You can take a look at benchmarks in benches/bench.py. Ratios are given against jsonschema-rs. Measured with stable Rust 1.44.1, Python 3.8.3 on i8700K (12 cores), 32GB RAM, Arch Linux.
Python support
jsonschema-rs supports Python 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.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 684231ec6c163f676f26e6add650dd4f1ec48ed4696e3cb1e07c397adf9132fa |
|
MD5 | 760b8acad0dd7ecbbdc6f6742e1464dd |
|
BLAKE2b-256 | 7e2f4a79c738a59da00e87ce0480817df9ed5f9a02ae6888fac18cf71d1b5acb |
Hashes for jsonschema_rs-0.4.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 337ba5afcaf546f4c40e174595042f0aeef62c0e31c9947593d9020369e5dad8 |
|
MD5 | 6e9722083005de3389938a774ff7e091 |
|
BLAKE2b-256 | e6edb3dc9e5093b0e7f399bc1bee3e0d9bb404b19fd6292a3b42efa909b6ed93 |
Hashes for jsonschema_rs-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b8125397b630554cb1f3d9b89d395143ecf682206070584e7cd972303cef783 |
|
MD5 | e63a07d7f6eedc5afa70840d2d0907e7 |
|
BLAKE2b-256 | 4157ef7dcf0369bbbfb7d421e6a32cf3e866a76ae555b86f8d4419299526500e |
Hashes for jsonschema_rs-0.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d451b164d69585f7cfe7f17449e94d1dfce97328dc20a7d92f8480cc2910112b |
|
MD5 | 91141f1150f90470b982ea8de7329eab |
|
BLAKE2b-256 | d981b66192b5737a6aeefe2924a40310c8e928b5a0c21aaab8d6805e7eac803b |
Hashes for jsonschema_rs-0.4.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eb76d87434085252c6eb9e07cfa4d7f745f28c4ad0812544578af355bcd39e9 |
|
MD5 | 825b8d3a17017306496fa11bf9a9f5d2 |
|
BLAKE2b-256 | a28279bdb27d619c07e10e1574cdf0eb5b766c7b78e0d695494f736677b4b271 |
Hashes for jsonschema_rs-0.4.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 587c978ade013eb2e175638773f3633779d34ddc1af55d41a42ae377af98cfa8 |
|
MD5 | 1b4156f26b2a3c61c548340dee01bfed |
|
BLAKE2b-256 | 5c945904b7791629c158da5ea16e9598800517f0e12c1d74ec2ee1d8f1d6044d |
Hashes for jsonschema_rs-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6699eabfaea2c3ef3f4bbf725f5a3599306947d8ea83a5d882a3f1ca5ee6a8fa |
|
MD5 | bc889015569b2f895d65ab946a8aff4a |
|
BLAKE2b-256 | 752d1e17a934e54729432bfb6dd148fd22b9984ad9a84f12404f3303c7e520f1 |
Hashes for jsonschema_rs-0.4.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d43680b31203840267c86fe5da58e3e2cf17d188fe3263fbf9b3d9f3b65d28 |
|
MD5 | a48dd241bdc76d411a43caf20af66128 |
|
BLAKE2b-256 | 3def73dc40e26ed36581e7fd1fc3ac9d5a399de718f6c8a818a06b81c2f21e38 |
Hashes for jsonschema_rs-0.4.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1786909a8415dd27c31c6bb1f0f557745c1b20d856e778ec5db693c6c41e08e9 |
|
MD5 | 272f052c307ecf730b153da2542cfb73 |
|
BLAKE2b-256 | 721a8d403f71050f4c53c312814a360172bb6150739998fb081315973e2f3cf9 |
Hashes for jsonschema_rs-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c91fd588df97243952ba571cbae73e2afe9662d450603fa36662c3ce59b82dd |
|
MD5 | 16b9cd70e174b8b6e7d9429673ea5755 |
|
BLAKE2b-256 | d7b533e40e8192a81093c7aebb712b4019da94bc72d0b24cbe39b77f7e340abb |
Hashes for jsonschema_rs-0.4.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aca2109b3fabbb4c2e4eac985c54b86497faa5fad6d631e48078e5aa4a70f2f |
|
MD5 | b56c246f2d86426521cd684a11ccdf8e |
|
BLAKE2b-256 | 3433e87acb1d9d2116db753a01f24275e10eb8ee5395e81082f4dd0e899fd191 |
Hashes for jsonschema_rs-0.4.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bd46afad9d596fe9055ea4b1a54ae0bc978035d11ce446adc845b4b7e8f677b |
|
MD5 | ce325bf427a920ab34efafe1693fa29e |
|
BLAKE2b-256 | e38a7d6f9b1f71fbbf38add236598235cf2d4a589134a4b7a83f8180ae778f89 |