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.5.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc58c8fdcfe8fd27ff683d1b51ea26b6200c588835b0b1102736754b1b5d489b |
|
MD5 | 23a24eec8afdec1eaf8f84c189b0b983 |
|
BLAKE2b-256 | 4e22f1cf0dfdb4b7c85789d2677b371040fe3f88a01df289b77b9f012cc88146 |
Hashes for jsonschema_rs-0.5.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbfc816d2211f7f26ab04239e24b36c8948f7940e361db26136ff264a4600244 |
|
MD5 | 7f31d0ce712aeec2135c9b9bc50e9d18 |
|
BLAKE2b-256 | a6aceaa64ec94d83da8727fb6f9be9fd8ab8b53c49836875a0c94e0dd516e00f |
Hashes for jsonschema_rs-0.5.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a331b67cf021f385aa314b67d12b397aa70215badfb94615c78edbc44259e9b |
|
MD5 | 7d89919b5a441fe6a65d2bc3b3e2545b |
|
BLAKE2b-256 | d21109eb7ab9544d3eb9f9d7b33005d4ee945660c913b6ff97360739b5014aba |
Hashes for jsonschema_rs-0.5.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fea1e08c77a4ef84ea4798a0250f351f6587e3af1a9d81a112ff1c2c01644a8d |
|
MD5 | 6b37451151353b6104e7b75feaab945a |
|
BLAKE2b-256 | 0c3b15a8518fbc645e68ebee33b8799c9f200134c66d34c57ab9cfd2be3b5866 |
Hashes for jsonschema_rs-0.5.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 364a7dacf18b01bbd9efdd8079a85f4985884729c7af8d6a869d9bacca0868f6 |
|
MD5 | 197433d398955e06986b0e785dc1e8fa |
|
BLAKE2b-256 | 4832d5c474e8da6573171975ac9df1656876cd745854dc665111f39a31744e60 |
Hashes for jsonschema_rs-0.5.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ece9271b8d8963c5d1c35a590df3e495cdf0a2707d788bb09f568df941e0d5a6 |
|
MD5 | 64e8a91852dc93ddbe2d3b9d870f2794 |
|
BLAKE2b-256 | aa95280f3518cdce3740e6cd19eb5c6e8b38698b891c2b9729c68079717c1bc9 |
Hashes for jsonschema_rs-0.5.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c09f72bd91ecd8606ca651d65d71b12957418b1c17aa677648b6993d81c909c0 |
|
MD5 | 9c47f6d27d13380cf40390a89a68e3fa |
|
BLAKE2b-256 | b5ffd69b20ac0d9b47de9fdc0732cd297efc0db10ef0439467bc26ab13e09605 |
Hashes for jsonschema_rs-0.5.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31b60016b9759ed0b3d8fefd13301f1dd22c395c99a73ce05d2be34f9d6b6e1d |
|
MD5 | b01c62636655b66e01a98c36c97fa4e5 |
|
BLAKE2b-256 | 33ac59bf06000441a2db29cf092a8f6ff6afdb685d706101bd6037bf9056c849 |
Hashes for jsonschema_rs-0.5.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e4c3d91091438b0c4fc73eabf49ca7f5a26c789751ea18b11f9aab52f950e2b |
|
MD5 | dc439348b591c29430eca4b7e142218b |
|
BLAKE2b-256 | dfa2b93b76394032ac4d7494bf2deeb40773545c18cc10a8b3846f9881f3cc66 |
Hashes for jsonschema_rs-0.5.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40ccddfec9bc186f93f2b3487054b96905389a5bc6f90a5a533edc35c8473419 |
|
MD5 | 5c46dc771f66ffb595072061c1e0ea87 |
|
BLAKE2b-256 | 3baa02920abe6ab65b6d02fcf847ad8efc66ee9b3ff738b7502fa23dd5f1c770 |
Hashes for jsonschema_rs-0.5.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e2f677c137eac4c2512aeffae25c140bfbae62c981a4e4b0c4fa40b2917345a |
|
MD5 | 38c18893a993c4c3c39f8d6accca7677 |
|
BLAKE2b-256 | 82ca04d132ebb878ce74257fda8519f91f3471ae388111b3cf318df718d251df |
Hashes for jsonschema_rs-0.5.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5c8827e6db17f204a38d9ae03488bdc2f42971ffa60ae9f515cd1ea31de3a8c |
|
MD5 | 1792f03a77e6b9120a7a7830e838ca44 |
|
BLAKE2b-256 | c1809a5211197608bf3296d69a2ba069ae26a0d7ac9108eee323bc422498cbb0 |