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 three variants in the tables 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.
overhead. Only transforms data to underlying Rust types and do not perform any validation. Shows the Python -> Rust data conversion cost.
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) |
jsonschema-rs[overhead] |
180.83 ns (x0.90) |
181.68 ns (x0.89) |
638.40 ns (x0.52) |
1.06 us (x0.70) |
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) |
jsonschema-rs[overhead] |
12.206 ms (x0.87) |
8.116 ms (x0.62) |
3.666 ms (x0.82) |
2.648 ms (x0.56) |
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.9.1.tar.gz
.
File metadata
- Download URL: jsonschema_rs-0.9.1.tar.gz
- Upload date:
- Size: 63.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e308f85354c9616a94e4f40b7a2154e47f395ccf1fdcdf1b6091e58f2f22661 |
|
MD5 | 0936868add8e64a5aae0acdf4ce0abb8 |
|
BLAKE2b-256 | a72cac7b3dca57a57b98c0aec9a4ca751366e34dd7c0d591663a7309d213401c |
File details
Details for the file jsonschema_rs-0.9.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34f7566c9ee70b6163dfbb3a1a7cada141f9daf466510f1ed0d1624fb89e942a |
|
MD5 | b96aae810e0323e33529733642583ad6 |
|
BLAKE2b-256 | 50d4dd2ad79ce1cda37b1bda3dac6d38a01d4acec807c19f46b290b4d2b8d0df |
File details
Details for the file jsonschema_rs-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a6dcaba215aab33da6334f44b9e63eb1a9a5cb27ddd164bdc7312580f50bbb2 |
|
MD5 | b68d3da9a4a077abd4dfbf8ffaf70e02 |
|
BLAKE2b-256 | 78919b005423623c062606afa0a4863bde62f355cee24e93422ba3f17b606176 |
File details
Details for the file jsonschema_rs-0.9.1-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5639fb6597fbf87f8439a875db145919453968b61f0422db5c7aa5f15af131c8 |
|
MD5 | f7c1041cb0062b541d5b3d3356d8154a |
|
BLAKE2b-256 | 7b763af15a17fa741f6ba41b4489fa5da14842290930469cfadf35c749398f09 |
File details
Details for the file jsonschema_rs-0.9.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f9af89fe53a06875b427148ca94d5d561b5f89c298a829e27217fc1ddc13d8d |
|
MD5 | 425ceef5907cac10b50d55c0e0545f70 |
|
BLAKE2b-256 | 496319e2cb35568149030e3d83c380c19bab7283974546aa039df1da9418cde8 |
File details
Details for the file jsonschema_rs-0.9.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0d2722ce156c190e70a80adedf3c75e1b33de0f914b22db47a64f56846f9b5 |
|
MD5 | 1071b0ea4c544f656901a202f7b738e2 |
|
BLAKE2b-256 | fc77e23bfa63ee351dad3c013f883849fb26d35162f6056c641314b57a34a5a1 |
File details
Details for the file jsonschema_rs-0.9.1-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb74c1caa4c0f7e14992586e5a0d71e3a957a05c3b7e677e013a475e5b96418d |
|
MD5 | 65e6da068bc1663bac5622ae7fc06b55 |
|
BLAKE2b-256 | 65ee2197e689bf5b41ace9241ed5794d77ba33be2ad8e724c4c13eeb346aad10 |
File details
Details for the file jsonschema_rs-0.9.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7251d664cd7d1165b3557364b9cfe7fc62db9e9a9175115e01fb4b1a7a195255 |
|
MD5 | a6e3e28ce80aa20411959f41261b027f |
|
BLAKE2b-256 | 5a7883fa981247391a0eab80f1a5dd49e6cf9f9a02dcc33461751cb68efc4a92 |
File details
Details for the file jsonschema_rs-0.9.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c89b10d4c295013546b25560a9bb3bba234e1f5c36d8fb1d08d110e6933c6bf |
|
MD5 | d495544dbaa33e2658831dc23a3c640c |
|
BLAKE2b-256 | a657af31eda7ba2353ee504146e1cfd9204ca9a8f9a6c2e26fedaf13a061603d |
File details
Details for the file jsonschema_rs-0.9.1-cp37-cp37m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c031e1ca4cc9f0300434ffb2140525849c79898d0279fd636d076b12275b286 |
|
MD5 | 674429e80276e8f8bc83f86de9cc9ee6 |
|
BLAKE2b-256 | 885ae5e7e2cf597c7efdce0ec11329dcd54857eded835c914ccc1c1115c1df6d |
File details
Details for the file jsonschema_rs-0.9.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90c57322165437490d7e416655e45ff7f05e8eb14ff3ab9b5f783a734e4088d4 |
|
MD5 | c521d6b656c3fcfc2001122640af1a26 |
|
BLAKE2b-256 | f078142dad3dbdbf895c06937dc8fdd13158dfc13a5313565a7439c1ad7a1e91 |
File details
Details for the file jsonschema_rs-0.9.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c68795ce33099fafb068848c579d82ed3bdf93cce85468cd60cbb9ae799e309 |
|
MD5 | ae597a9c5e68567b77c504cc5f14121b |
|
BLAKE2b-256 | a0d7b6cf9f5cdb7f9016b1fb673400ad22e5cd58dbf4127db261f9ba7c18c1a4 |
File details
Details for the file jsonschema_rs-0.9.1-cp36-cp36m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: jsonschema_rs-0.9.1-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.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d618f857c01b38fe1666cad1a16064f8364ed92eab00cd2f9069b267297745 |
|
MD5 | aa6f1dd712f5ecb37a1a2ad80d76a217 |
|
BLAKE2b-256 | d9a898ee3db038278cde2379ed0aa775ae43ef2f249add1d87db7acf36b53d7f |