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.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ce2a349fdcdfce3b3265709b62338306e8a3cb4480c24645e70996eaf9a723 |
|
MD5 | cf2bc51782802d005671a4f6e8488aff |
|
BLAKE2b-256 | f1236747ce29252b67f41f9f2182f0dd2994b7e67520d7abf295c26eb2bfe75c |
Hashes for jsonschema_rs-0.4.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8103b249c850728e7a2c2e259f87c451f338bc39741d13172a195e2409597d2d |
|
MD5 | bb8a70a0b4afcf687455e81d031b6cfe |
|
BLAKE2b-256 | a68606461c7ed2b7d57006953f2782d6e5520538abdd118f4f37ec675a4fe5d8 |
Hashes for jsonschema_rs-0.4.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ae9d78b74b993c982303abdf7f7f36160c078ba4d05997c581c94253206b947 |
|
MD5 | 45db938673e19f422745ff77d865c4ab |
|
BLAKE2b-256 | db3229ea8f03c3edf8a609561f42ef1e9d5c79afa67b230b10c033d1681b67ae |
Hashes for jsonschema_rs-0.4.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75d91ee4fe893b69e478eb9acb4a8c0825709cc0940cb21a0d9e138e92852f90 |
|
MD5 | 99a08fe667bc71ed6f27edd9cb8f1b2c |
|
BLAKE2b-256 | add88e328e755786daf77cbeadf353d1534a2df9e081ce03941211e29e7b444a |
Hashes for jsonschema_rs-0.4.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a46f5e30d4ed9f088422acebf80fddb04dad90863c8e04d6727145a32f153a |
|
MD5 | c08a5a95fc4787a6eb35d56b5eea184f |
|
BLAKE2b-256 | c27a3726d5d242bfd72c99088817d9340c6a0ed3e9e2aa8cffd01c221611b4d5 |
Hashes for jsonschema_rs-0.4.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb93511a565bfff78e41ffad34cb93e2d0ba2aea8add0fd358969501bfad40e |
|
MD5 | 36923fbdd0a0ef4447b6782473ce5559 |
|
BLAKE2b-256 | e576c0828c68d4f433f350f8a75d3e378dce884f2775972e21a881be89ce0aa8 |
Hashes for jsonschema_rs-0.4.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eac5f536d86fc90625d2a88764e1d53d60fec9bb09517daa9bc42e4382b8434c |
|
MD5 | 64eadbad8bc049e9a605c3fc4ec390ec |
|
BLAKE2b-256 | 8a62054af9519d7b46637848d0862bada1470ee6170bce72d22dac8fc432e0a1 |
Hashes for jsonschema_rs-0.4.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a39c072d9e773fd3ae7bd8a5a918b70b46f09f7a540a84679e9f747af04975a |
|
MD5 | ea6dd1fc76eb0ae070ececb42446607a |
|
BLAKE2b-256 | 128e5c9b6d053846de0dfccf79d4eb7a265fcd88ae1b23603dc7195a2c796cb8 |
Hashes for jsonschema_rs-0.4.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c0060618249abbc33cf37b32e38a1834dd51a1d0cb1edc38557ee18477541c5 |
|
MD5 | 108e8fa0af1d97a8c3038c169010e0a7 |
|
BLAKE2b-256 | 69ffa5c0016e2b2a792fb6919e73900756cf5edc1dff4a57387470a9cea5ca23 |
Hashes for jsonschema_rs-0.4.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fa6ae958d6ad7214ea0f1c3a795055ca7d969147caaea36aaa2c0be60408b5 |
|
MD5 | 7203488f9c289f76f00c062d59f027c4 |
|
BLAKE2b-256 | 918221976b2d3da1d13eb12516f1eea8017d3bf915384c27a40eb106ca13e77a |
Hashes for jsonschema_rs-0.4.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 961aa762966fc694d9924c199bd37aa5a0afda4b3c4bb7ae757b253b41c89770 |
|
MD5 | 98a319332586647d304af73b8f581fd1 |
|
BLAKE2b-256 | 3c79cafc7fbc3a3bd60afd38f49a2de81b0c5db457155ecd957abfa06bcae4f9 |
Hashes for jsonschema_rs-0.4.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce194153b328f50c179b09d6dd57239c64009611f4e8a9282d681e5b9fea77e6 |
|
MD5 | 3d73bb8a6438c6b8a2439769d5130df8 |
|
BLAKE2b-256 | 88f67156e10ecec8207b71f829d4d0290a5abebeb93415ca3523631fb922c0d1 |