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.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60fc9d40a614decd8a4444c4af23a5cd3e8b2337a471ef8678b9a3865b994fb7 |
|
MD5 | 12bf36a46fad0bcb8b0fdb3b745210b4 |
|
BLAKE2b-256 | 0f4d960ace9db4320ab3e4f34fa7089c62a52e4963eb3636af5f26cc10897e72 |
Hashes for jsonschema_rs-0.4.3-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b13f4061c8e045989206851533155097d9aca6fbf3b38c064b336e86d3b801d |
|
MD5 | e54a354547c92b3b31bb7b96f09a1e11 |
|
BLAKE2b-256 | 5ccbe1134431e062d063f5fecdf69618bf5c06c66b8a7164c52236a88a602546 |
Hashes for jsonschema_rs-0.4.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c409e41dcea1fafdd393ce0233c82ae79c95cfddd034ed432bd2c8e52ed685bd |
|
MD5 | 95ecd9a5afba438c98f4da5a79e1dce7 |
|
BLAKE2b-256 | 2547a105308980e8c57ef712780960d32b4777c77914391776717053f66f0cd8 |
Hashes for jsonschema_rs-0.4.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57d19d34be00a5cd827950e40fcd5f163b60f9e1f562510249b3656a8e068de0 |
|
MD5 | 97632e58882d50d1975a90a8afe37bc7 |
|
BLAKE2b-256 | 1e8504d83310d5973ba61a32965f71b3f62fbfb268728557f17f27bdb95d4975 |
Hashes for jsonschema_rs-0.4.3-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06f4dacec00684d67166699ac5c440c020e63fc79f0c9a573392af25edaf6c74 |
|
MD5 | 9e4329dc46ef48b535cd825bca7ef6a3 |
|
BLAKE2b-256 | 5473f07e3acd6b088584e18e77305255c2e763a90fb35805e6eec897aeb0cd11 |
Hashes for jsonschema_rs-0.4.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39cf11871541d415d2f00c0ad49a25e3fca4f9590adf7f52b60bcfb8b575e8b3 |
|
MD5 | 700bd7006a7096b5ea36fb2abaa2019d |
|
BLAKE2b-256 | 895967c8e1cd78f9b54e3d866e1eb7f0db8135dbc8254fbf20012af91c4efac7 |
Hashes for jsonschema_rs-0.4.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efa119ee30bf8cad60ab5a621b6cd486b671274d07a8768f5cafb2635829cd5d |
|
MD5 | 45ad7f425342a7751a78946c1f4d63ce |
|
BLAKE2b-256 | e4fbe2d0326ee0bb8c1eee4c94005a63b10578ed12b9d73d6c114805c346ef0f |
Hashes for jsonschema_rs-0.4.3-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 590e693d67a191151fec71a4efefbecee93a268954be28ceae09dd09f9f59ccd |
|
MD5 | bcf8d7e066d4dccad98d9def6d448031 |
|
BLAKE2b-256 | c5533c8daf114c853d56219bcd9c770584fba0e886020023d0969cb39c9c4b40 |
Hashes for jsonschema_rs-0.4.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e767dc79b74e445fd40572128e14fbd686aee32da2211852dac41a943aba79db |
|
MD5 | b2c97ee051c3d01f13b176d6babc050b |
|
BLAKE2b-256 | 032ec08acf96a8fe348253b3504ec040cfc51190ccdbad188b5d643f10a88db4 |
Hashes for jsonschema_rs-0.4.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54904473594c37dbe921ce41312d89ffa990cc38818e533946a6929e844aff61 |
|
MD5 | be3c261cf8c532bbaaed6b77528f53fa |
|
BLAKE2b-256 | 4e0339cfb941296c5fa08ad4a8aa6a7ae499b45cb061f7b5cd70181a8031a4b3 |
Hashes for jsonschema_rs-0.4.3-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39e154df25fa59c7c79f2f61998a4f307b5cf7e031349b8fc46c99f0748e6962 |
|
MD5 | 660d3ea9f3396d76b98250d6dc535ec9 |
|
BLAKE2b-256 | 01e0af6f94bd2ed3023cbfb8c97491bdb74dc897babdc7aee81fbef0d6984acc |
Hashes for jsonschema_rs-0.4.3-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a23b674660be674e47176df91b792b93a53a5205917102cc8801be9084bf4258 |
|
MD5 | e66e14e07dfbbb84447ddaa1394f014d |
|
BLAKE2b-256 | 102ef0cb8576a89c39b4b010827d60643f9c03826adc89c8177d7005ac79c67a |