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 small schemas & inputs it might be slower than fastjsonschema or jsonschema on PyPy.
Input values and schemas
Zuora OpenAPI schema (zuora.json). Validated against OpenAPI 3.0 JSON Schema (openapi.json).
Kubernetes Swagger schema (kubernetes.json). Validated against Swagger JSON Schema (swagger.json).
Canadian border in GeoJSON format (canada.json). Schema is taken from the GeoJSON website (geojson.json).
Concert data catalog (citm_catalog.json). Schema is inferred via infers-jsonschema & manually adjusted (citm_catalog_schema.json).
Fast is taken from fastjsonschema benchmarks (fast_schema.json, f`ast_valid.json` and fast_invalid.json).
Case |
Schema size |
Instance size |
---|---|---|
OpenAPI |
18 KB |
4.5 MB |
Swagger |
25 KB |
3.0 MB |
Canada |
4.8 KB |
2.1 MB |
CITM catalog |
2.3 KB |
501 KB |
Fast (valid) |
595 B |
55 B |
Fast (invalid) |
595 B |
60 B |
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.
Small schemas:
library |
true |
{"minimum": 10} |
Fast (valid) |
Fast (invalid) |
---|---|---|---|---|
jsonschema-rs[validate] |
200.82 ns |
203.10 ns |
1.22 us |
1.51 us |
jsonschema-rs[is_valid] |
187.60 ns (x0.93) |
185.24 ns (x0.91) |
850.25 ns (x0.69) |
1.18 us (x0.78) |
fastjsonschema[CPython] |
58.57 ns (x0.29) |
109.10 ns (x0.53) |
4.16 us (x3.40) |
4.75 us (x3.14) |
fastjsonschema[PyPy] |
1.32 ns (x0.006) |
33.39 ns (x0.16) |
890 ns (x0.72) |
875 ns (x0.58) |
jsonschema[CPython] |
226.48 ns (x1.12) |
1.88 us (x9.25) |
56.58 us (x46.37) |
57.31 us (x37.95) |
jsonschema[PyPy] |
41.18 ns (x0.20) |
224.94 ns (x1.10) |
23.40 us (x19.18) |
22.78 us (x15.08) |
Large schemas:
library |
Zuora (OpenAPI) |
Kubernetes (Swagger) |
Canada (GeoJSON) |
CITM catalog |
---|---|---|---|---|
jsonschema-rs[validate] |
13.970 ms |
13.076 ms |
4.428 ms |
4.715 ms |
jsonschema-rs[is_valid] |
13.664 ms (x0.97) |
11.506 ms (x0.87) |
4.422 ms (x0.99) |
3.134 ms (x0.66) |
fastjsonschema[CPython] |
– (1) |
87.020 ms (x6.65) |
31.705 ms (x7.16) |
11.715 ms (x2.48) |
fastjsonschema[PyPy] |
– (1) |
38.586 ms (x2.95) |
8.417 ms (x1.90) |
4.789 ms (x1.01) |
jsonschema[CPython] |
749.615 ms (x53.65) |
1.032 s (x78.92) |
1.286 s (x290.42) |
112.510 ms (x23.86) |
jsonschema[PyPy] |
611.056 ms (x43.74) |
592.584 ms (x45.31) |
530.567 ms (x119.82) |
28.619 ms (x6.06) |
Notes:
fastjsonschema fails to compile the Open API spec due to the presence of the uri-reference format (that is not defined in Draft 4). However, unknown formats are explicitly supported by the spec.
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.51, CPython 3.9.4 / PyPy3 7.3.4 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
File details
Details for the file jsonschema_rs-0.6.2.tar.gz
.
File metadata
- Download URL: jsonschema_rs-0.6.2.tar.gz
- Upload date:
- Size: 62.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 029b2daa1b22e45304ca7bbb02ef7c5009724943c7449c227836aa75a14fdcc7 |
|
MD5 | 54fe3b10c9110e9e035968ee04ebd0e3 |
|
BLAKE2b-256 | 52c9627dd3782f07d9b94311a854b5f4bc836c4c26ba7c30f96f78891f0174c7 |
File details
Details for the file jsonschema_rs-0.6.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0068a3d55c94f0fc50baaa5e6ef5b7e94da62884fad6eac4119c021a55bd63e |
|
MD5 | 3a9b71a8efe509192f7cd90760ef9219 |
|
BLAKE2b-256 | c7a9a89ffe0b791b71115cf5ade892af3a2b42972f025e4f9ddfccbc766fb677 |
File details
Details for the file jsonschema_rs-0.6.2-cp39-cp39-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp39-cp39-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ef18ce11b0b9a0736f5fa0a2065a912e0ba4f584a1c76014bfdf1d170802011 |
|
MD5 | 72e253427c9a7a3e498fc57e659ad007 |
|
BLAKE2b-256 | 7fd28b069dbcea9fcb4976408800142918561e1db09826d88921c3d3a7957514 |
File details
Details for the file jsonschema_rs-0.6.2-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3addb6ab29b346f2fb2b3c9b17936cd5305332eb946b66ce11cd412697de921 |
|
MD5 | 697637f125a39ae063170c1c51a9c5b2 |
|
BLAKE2b-256 | 1b3d3bb88bc1c9a26c2b9aeda0745c94fcd3456f9242cbd6be8c479628854186 |
File details
Details for the file jsonschema_rs-0.6.2-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23961fe64fc84796b7f5115b5aae3c6a3e7f67f9f905c0b710b377c11882d851 |
|
MD5 | 8afbe31dccb26dbf43db0a0f69743b1f |
|
BLAKE2b-256 | eac7808acf077362a1bb3a41bab787c0623bda94a268b2a7d5973925606ddfcf |
File details
Details for the file jsonschema_rs-0.6.2-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 296948bfeb0396a274e9773834d28dbc1060132863aedd9fb95a0f84e3df651e |
|
MD5 | 5a7e080db5132366b80bcf40e37d8086 |
|
BLAKE2b-256 | 7df84a362c839d074d5f1f3d7b001c84d37525b957be8e97fc1d0b5f141f3fe4 |
File details
Details for the file jsonschema_rs-0.6.2-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 045db594a42c61cb4453f9ff531c2d40257f1c933e6e6e7455930cbc3dde033e |
|
MD5 | 44c5392e7db956290d9846d19dafdafd |
|
BLAKE2b-256 | 250e403a82be78ad86f7640565692855a9297831454b3d9d43c2ce1d41d1fce4 |
File details
Details for the file jsonschema_rs-0.6.2-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2690945652edc392b11ac3d41d6945b7c71c4daf3519136728070b22bf88ed9 |
|
MD5 | 43c5f1a802c29c6337e5784f00874a97 |
|
BLAKE2b-256 | 1c9bbe3449d972c2c742b1466b6727a39fed64899984f99dd76cb32cbcb5b38b |
File details
Details for the file jsonschema_rs-0.6.2-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5498455ac073dfa057df365f10910bdbbc122a900cb4e1e505b1fbf8f7479507 |
|
MD5 | 12c1d60134ed8fdb8d1ea2149613e6aa |
|
BLAKE2b-256 | cace3af3c54fd8e3fbf7494d5734151a28cf93ac4b15fe43ce544e374e83a774 |
File details
Details for the file jsonschema_rs-0.6.2-cp37-cp37m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp37-cp37m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.7m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8da7972bc0c6342a36bdfb3fcfcb9c0fab5a2904334ebca208d655163580fae1 |
|
MD5 | 8f9c650368174e4d0d7e53ff941a5d41 |
|
BLAKE2b-256 | 06d29996e75495c5e84af80d6f924ced29e6d6d59db77752556a3a4948c41a31 |
File details
Details for the file jsonschema_rs-0.6.2-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77b1babf535d733fd67b87f8a01288b87308375455a2ae222f3f08fbef0c9ac0 |
|
MD5 | 9c1d2e360ebf7737e41ac00e60b3d97f |
|
BLAKE2b-256 | 33ac2c0cee52dd053effcfec56ffac31d8294cf539a8f941fdb52ef7fd24a4a5 |
File details
Details for the file jsonschema_rs-0.6.2-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8801ef78132ebb5e86e2a0125233d4cae012da480f3fa7ff41c233d1e62ea532 |
|
MD5 | 3c89143220e654a969b623a5d91489dd |
|
BLAKE2b-256 | 7c22bdaf32bd0fbcb8271621a9f94b12e09ab35a538212a3bf9b3f960d730b46 |
File details
Details for the file jsonschema_rs-0.6.2-cp36-cp36m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.6.2-cp36-cp36m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.6m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e86ed3ff016edc962cfbc70c0235570dbd5c1d7c7fbf4d73a3c91c29aa15f9c |
|
MD5 | a490964d38ca49c0a5ffb1dc97d3b9f1 |
|
BLAKE2b-256 | 694a7da9869e96f2bd9cf45d696f61857b176dfb0dfa009e9163a5feb2b196cc |