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 or jsonschema on PyPy.
Schemas:
kubernetes-openapi is an Open API schema for Kubernetes which is ~3.15 MB JSON file.
small is taken from fastjsonschema benchmarks.
Compiled validators (when the input schema is compiled once and reused later). jsonschema-rs comes in two variants in the table below:
validate. This method raises ValidationError on errors or returns None on their absence.
`is_valid. A faster method that returns a boolean result whether the instance is valid.
Ratios are given against the validate variant.
library |
false |
{"minimum": 10} |
small |
kubernetes-openapi |
---|---|---|---|---|
jsonschema-rs[validate] |
200.51 ns |
203.30 ns |
1.09 us |
14.97 ms |
jsonschema-rs[is_valid] |
186.00 ns (x0.92) |
186.79 ns (x0.91) |
884.40 ns (x0.81) |
13.94 ms (x0.93) |
fastjsonschema[CPython] |
58.57 ns (x0.29) |
109.10 ns (x0.53) |
4.21 us (x3.86) |
91.79 ms (x6.13) |
fastjsonschema[PyPy] |
1.32 ns (x0.006) |
33.39 ns (x0.16) |
1.17 us (x1.07) |
44.27 ms (x2.95) |
jsonschema[CPython] |
226.48 ns (x1.12) |
1.88 us (x9.24) |
58.14 us (x53.33) |
1.07 s (x71.47) |
jsonschema[PyPy] |
41.18 ns (x0.20) |
224.94 ns (x1.10) |
25.97 us (x23.82) |
663.30 ms (x44.30) |
The bigger the input is the bigger is performance win. You can take a look at benchmarks in benches/bench.py.
Package versions:
jsonschema-rs - latest version from the repository
jsonschema - 3.2.0
fastjsonschema - 2.15.0
Measured with stable Rust 1.49, CPython 3.9.1 / PyPy3 7.3.3 on i8700K (12 cores), 32GB RAM, Arch Linux.
Python support
jsonschema-rs supports CPython 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.6.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3de0945183093bf631f26388599f2ce8ecbce794607e1252fcf42de71fa6e9a1 |
|
MD5 | 405a7f94ce33ad8bacf7e26bb81b91a7 |
|
BLAKE2b-256 | 2b633f880444ab1330a415a8090cf03c5de2829415192e7d6b45cbf4298b8f8d |
Hashes for jsonschema_rs-0.6.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c53c23be970613b3d9ec3329130d4ecab856f90353168a5e92393d632b413584 |
|
MD5 | 352cc12e17aaf47068aa771f394059e2 |
|
BLAKE2b-256 | 9740bde7b5b7e05a0daf3e5e3d9794d39e567369b3e184dd10e3c51291d2ace4 |
Hashes for jsonschema_rs-0.6.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c928eaa230766f403f295945a56de185be3c6f99e1d68ce65535ddd2b08d1a93 |
|
MD5 | 0c876aeaf2e49459fb93eb39b074410e |
|
BLAKE2b-256 | 4b88f63f96d733a974c5f7ea52de936821f9c1d51285b9cd28aa785acdd79bea |
Hashes for jsonschema_rs-0.6.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | accb80149173752aba84f6cae695657a04831ae8e68278aa0be5ba84853d0397 |
|
MD5 | a6e4e17689f43dd7f0be81f892606ef5 |
|
BLAKE2b-256 | a59e27026d70592228a78ee7aaccd566bd91bb720be0e1e6e36deef604b9ec5a |
Hashes for jsonschema_rs-0.6.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 897d423a47796580843f536f864eba518be006f6585b370e5b2e3982506290c1 |
|
MD5 | c3c4842e5c7d196a1414ef3583dca6ba |
|
BLAKE2b-256 | cbd686e5a6081ef596c971aa1d10ee995bec194c85092e797147061b7b28756e |
Hashes for jsonschema_rs-0.6.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b6cf58e49d6931c855a351e496c2d3595c5133bddd24c5401b2a5c6c502c39c |
|
MD5 | bf2c26ffe9eb2e21f4c1e13ac0ab2e72 |
|
BLAKE2b-256 | be6cafb8f5c952d63d970a9b4bc432b3a91c61e50916ca8b22f1ca65438b12d1 |
Hashes for jsonschema_rs-0.6.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 687150c795e9d12e59fb044cd4ff4a8c230660e14b3d2946f2f30397835b5057 |
|
MD5 | 1654c6422917e7ac7f9e58309d50a41e |
|
BLAKE2b-256 | 13f062bccd3ad7811b7b5f784df749920d7e29c9519c7e977d52a0d00ba0fa9a |
Hashes for jsonschema_rs-0.6.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d5ff112e38b856f163a8cb826325efa2b7eaa1bd5bd88de01fd11c7e7c2b417 |
|
MD5 | 93ba5bc31401848143d79fa18c2d9632 |
|
BLAKE2b-256 | 1ce34ab4bddff339a11a34214017087c88be465c43b208c6921eba1547e8ae27 |
Hashes for jsonschema_rs-0.6.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 929925a83f7cf2e27e482d6eee5a43d44867ab0efd8b55c2b2ce3d951fc08279 |
|
MD5 | e562fb8dfd8a950ae130e70dc9bc933d |
|
BLAKE2b-256 | 67bba9e460772f5a0492459b136a591d68c79ceb4b8a5f6ca1963647653b5c6e |
Hashes for jsonschema_rs-0.6.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4540860347ab0ef8da53a322809afd44e5be95c23aae3e740cb5d417570da00d |
|
MD5 | 7b3a3bbd47966b17e13dfd1e9b0a13e7 |
|
BLAKE2b-256 | b792c6efce5657391c8088b5c53a0f33a9abf1e55823c95d1301a2741c2626e6 |
Hashes for jsonschema_rs-0.6.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55e021bb9845d7c4cc04b5001b75de5abc010412dd2e0bd69658bb561653d0b3 |
|
MD5 | 82d97f81402f86171d62a2e2964d9b10 |
|
BLAKE2b-256 | 8e06b8036003c9040088b48979a8684bdd27ff677fc532d4948449e5f41a7c41 |
Hashes for jsonschema_rs-0.6.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30b8c220dafd42eec681d5fa9abd1266d5acd5ac398b3acf83f2e12d80a1a849 |
|
MD5 | ce46457fd9cabf8f18a5e2462f0a0f84 |
|
BLAKE2b-256 | 88262223954eb5e598e33dc17066b8f778e794926b918a94af6925afa50ad689 |