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.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 935f54605fea7c95268ec60b6791af86fa5c706de18221bcdf00a78363c87b7f |
|
MD5 | 9fff8750e438905bf04c33f9eeaca336 |
|
BLAKE2b-256 | 5f22d9bd6a1a0d920db4661065f0e21fb79e9ac1646dfc718fcd504a53bbd852 |
Hashes for jsonschema_rs-0.5.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d2ee1172eb550de11909d9a109d2cbae7003b403045f818f97435de3a84074 |
|
MD5 | 7ced06a6184790fbf8fb3e54e5f575a1 |
|
BLAKE2b-256 | b3f5a5408a42e5338e96b67f7bfcdf76a02dbe90aa3a2433e524f04d81e67931 |
Hashes for jsonschema_rs-0.5.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfb70ecd5a1bcf2819c761bef972191c4bf460fa3211d63fc6dc0e6d4f756651 |
|
MD5 | b55e856863d89e800f9fc67b7a85a3c8 |
|
BLAKE2b-256 | 032a3793a7aa436af694c03f72afae28d3c5c7568076acb3ceeff2792724ba50 |
Hashes for jsonschema_rs-0.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f77fc1ca5a465547ff6daf7edb657cedfcb35054844c5386e05194d3796bad6 |
|
MD5 | c5c67869708ec5e0ead3d0d7af45750e |
|
BLAKE2b-256 | c9bacad1b5dfcd29bd7f43422a34508576ad4882d59ea1a2c5eccdbc9f3aaa93 |
Hashes for jsonschema_rs-0.5.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a93a8bc3285dfa642a146e075d471ff5feaf727ea90e223450d1890d92a37e1 |
|
MD5 | d6a659cdd84190a10c18385d3085032a |
|
BLAKE2b-256 | 4f62f0d22275c19faa478249425355b7f44ded7bcd46cc38cd219c36a78f5592 |
Hashes for jsonschema_rs-0.5.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b02ae6814d6ab25445032cf2d396398b2e157f4358303237a5849e53690c05 |
|
MD5 | 55bc89ad59b91ad3356070e6a8313931 |
|
BLAKE2b-256 | 3081fc34cd337cfa5dcb74be040242c137472a713a992268b31be36cb619afcf |
Hashes for jsonschema_rs-0.5.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60d7dfbbfec54ce336f6b9826f9bffc26ff484c52ede5b23aead0eb583965d76 |
|
MD5 | 09c6e501d7140786a38ad528ad0c99d2 |
|
BLAKE2b-256 | cdf347e88c79175dc49661e3dd7c81a2ce019125c8c577f33af4d880cd34c94f |
Hashes for jsonschema_rs-0.5.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a17e3ef0ee0aae5bf3dffa55fcbfcc062f5125fe5455b38b91a6279648416d3 |
|
MD5 | e632a6966d96312530a18715275ef97f |
|
BLAKE2b-256 | 034a12ffa248566808671d06489da3f1f38386550e46e0a95acc0359984c5ac8 |
Hashes for jsonschema_rs-0.5.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c74f62bd049512998b903c7924ce3be7c65c286cf79098583c53218d078d407e |
|
MD5 | 0b2d27bdc6840d2b5b3fbb566c36caaa |
|
BLAKE2b-256 | 2aba57b419841700beb3872816b9d7e204934cdcb68129d31daff17dc97f96f2 |
Hashes for jsonschema_rs-0.5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89ab80db839ebbf8080296de8c001c7048c2ebe782008835850f2f388578a01 |
|
MD5 | ed700509568dd08fe5f60eac0d00cf19 |
|
BLAKE2b-256 | 38e14ed46cadb80cc9aff5ebc0c1469ed93c11678df8235e86749f20d982bb0c |
Hashes for jsonschema_rs-0.5.0-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f8d59db8ae4c3cbc807e69bbb3957048892fbbe2c4b0190561f8941a0187f04 |
|
MD5 | df3c863db54cfac0fe589a3ed53c42c1 |
|
BLAKE2b-256 | 5528e067c3ba9fa4640122f0b432ce00ded8c1b3587f2c5081cb473a17b8cc34 |
Hashes for jsonschema_rs-0.5.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffc6e3848e53b4efe9b25114f4aa09001d50aedcca1e5a47629466db8958d5e6 |
|
MD5 | 856302eab17030033954a2152632ebc0 |
|
BLAKE2b-256 | 22971e1b36a3812d076711f15b1cf128e3f96075c16e04ac79d15be86b9c8f87 |