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.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff6bda5e7af2796df2067c484cddcb5de29c149b501eb8339bbe53d4d4f1ca0d |
|
MD5 | c582ff36659b2e3474bf2c72efd9d84f |
|
BLAKE2b-256 | 9609e3a0853d81d0765288cb0a5c5bb9cf822bacfaa7547a5d8f9affdf8e3c74 |
Hashes for jsonschema_rs-0.4.2-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b00dd352a841069bcd17d61566bd7f21389376457e2491b2cad487d3868cca1 |
|
MD5 | f69a1bf253362e957eec5a18bf129d2a |
|
BLAKE2b-256 | 47c7527ef0482f5e16f117e06e4b4f3b308460bbab1e37acd62e80378fd64dd6 |
Hashes for jsonschema_rs-0.4.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89d0ca051d99034ea3b2ae822c4075d4a0e4448f2559791c740c04f4d943a65 |
|
MD5 | 564c4001b420f21accb538788d72c96d |
|
BLAKE2b-256 | d1f346280115d9085d46bc687729eb3f5fddbcc1ce4ffe2df4d0e10c37f97e5c |
Hashes for jsonschema_rs-0.4.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8665092fb8f64df269f3606d755d0cd860be8b29ba374dd4f730fc5d37a60111 |
|
MD5 | 9d41e9c4591c58c4a32694ead429a547 |
|
BLAKE2b-256 | d2265be3862c2bcac3431eb33948cd3db9fef2e774db4501faff86a029426965 |
Hashes for jsonschema_rs-0.4.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a6d2bbeff2271a60c22b769cbb1013e8ed1e9114765aaf4022b7231aa0c888e |
|
MD5 | 5b87a1c60a16fc8e40eb76f5ab1b00d9 |
|
BLAKE2b-256 | ae4a459e2706e1906a9b2d2c5eb2f6fad3736cc79057485869d219320ca44b20 |
Hashes for jsonschema_rs-0.4.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 827887004b4ba029d8b0e86c770b06dc8267c9adb7ff4316f1d01433158d8e46 |
|
MD5 | ef96e26b2e2e469c550f1568997b32d5 |
|
BLAKE2b-256 | fb5e340f1cc13b69a9dc6e0cc35a3425a9718b91b3c3ef940ed5ef6093202d2e |
Hashes for jsonschema_rs-0.4.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a983b3d25378de4410276dbcda23d43a7972b6fd22d0ad7cbcf78c895f9cad2 |
|
MD5 | 94b259bdd4b602206b51718aa092acb0 |
|
BLAKE2b-256 | 765288f298d22dd941c7cd475d5b8ea651797363c9877647cb104e6e62a8bf77 |
Hashes for jsonschema_rs-0.4.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99ffc142899a928404b6e27f6f5318eb39d5320ed8c3fd97cabea4af9884284a |
|
MD5 | 18c66363994d6a4648acb1dfb5aae892 |
|
BLAKE2b-256 | e7bcb891ad0095510a0a88dc33c2c5ca335c78dcc5e36dbe995fdc962c776f93 |
Hashes for jsonschema_rs-0.4.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30f55850e2fe31937e053b154bb7f574f43e15577e25a1448a1d82426ee6cfec |
|
MD5 | 60f089b0a08ba0bf15ee3d16f64bc6dd |
|
BLAKE2b-256 | 21d4516864246e89dfb62bf3d938a08ff3015f3165ff45c981fd0e5f338c166b |
Hashes for jsonschema_rs-0.4.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bb91ee68e078b0df1664b96d4a1ccb305c32416abd23f7bb003077f9a04b475 |
|
MD5 | 506595854251f60f9c99d273801d19ed |
|
BLAKE2b-256 | 0974bac1472ab96e5a8ddcf177e7620f6427691109fe3a577a58b225490588da |
Hashes for jsonschema_rs-0.4.2-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5643989b95b73a7171cf94174340c43afd7249546ed579ac3d55d27d60822e3b |
|
MD5 | acdfd8a5c1fda847a54e3c0377d53d10 |
|
BLAKE2b-256 | c395952672ef211f935a0f95eafef9cc50243a174265c6e6bcf9eaa30b41b5e7 |
Hashes for jsonschema_rs-0.4.2-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ac50a9fbba716bd1604e50c90a18f237ca2f2b8c3e57cb665291d4f1e9da37a |
|
MD5 | 3c7586b4127c55d37594fb9124a6fa10 |
|
BLAKE2b-256 | 8a7973ff19696cb3706a29c3866ff12c2177dac6ca7f880c628483c7b9f7a886 |