Skip to main content

Fast JSON Schema validation for Python implemented in Rust

Project description

Build Version Python versions License

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

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:

  1. 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

jsonschema_rs-0.10.0.tar.gz (64.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jsonschema_rs-0.10.0-cp39-cp39-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.10.0-cp39-cp39-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

jsonschema_rs-0.10.0-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.10.0-cp38-cp38-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

jsonschema_rs-0.10.0-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.10.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.10.0-cp37-cp37m-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

jsonschema_rs-0.10.0-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.10.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.10.0-cp36-cp36m-macosx_10_15_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

File details

Details for the file jsonschema_rs-0.10.0.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.10.0.tar.gz
  • Upload date:
  • Size: 64.1 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

Hashes for jsonschema_rs-0.10.0.tar.gz
Algorithm Hash digest
SHA256 71d6426087b9b1994657537a783ecb6d1e66456088c534a0d14fe04991bd1d80
MD5 27846560817d0975d2134d1ab129bb9a
BLAKE2b-256 d7f7ed10ae9decd23e001f884f930f9a798a035f64128fe2bfb99484207ba047

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 adde976f119af133d22e538acd45cc721bc77565423a6275cabd53dac2053a4f
MD5 73fdd0d39089cdf8119ac988a686abd7
BLAKE2b-256 87c867cc6bc05a6f7f85b7fb7f3054d7b56cf2303dfb4510b25de6584afc94a5

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9bd5ef7e505939932e3c2affaffc6a05a0b752f1357b7411d84a02d933ea1ccd
MD5 dc127785ec65270bb2a02d6fa1a9f97e
BLAKE2b-256 2d2f8206d45b2600128d45e092f54b32e5a3af4f5da379608b6d08b6d2c69b23

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 097fcd39644ef58f735fa275864714092a4cc64e783ddb3b7b1216a5a7f4b7a5
MD5 69da8579dbe185600e7695f1f1d2061c
BLAKE2b-256 4857e5e54ae15df76706dc2c89cace51d9fc7ea11831d67d43472de16a4cc05d

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5a76674c10cb0a4cfd0718eca08410edba9ddec34a9e8fc4232bc5fb1a2f6d8e
MD5 06a7fe4f952debb4c139df00e9101dc9
BLAKE2b-256 af8523622579dea74dac4cd88aaf247abebab1d8c60c5a97e45fd38e06ed8907

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8894a14ef2886552982bb312f29cfe23b7ef9b43c702abb1c650784872804047
MD5 8344b652d26def55d283c6222fa6649d
BLAKE2b-256 e0bc70d4491971034c53d4c11260cf19030e38699e38c121fefe7d5998160436

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3b0fa2ac6596334bd12118ea06a4a6bc020cc5191f218e4ff8857bf45e0afc74
MD5 b7d6acff4b6d64779d8f1c71929421b3
BLAKE2b-256 027eea4e08db2b1db596164d46ffc482261d0ad4c84b663bf2483a36b8320b46

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 29bacef472c87708703e1cb8d586b7c4044992fa59b384ef96e5e141899419e3
MD5 e7e58102dd7663264c86ab897a7f07f2
BLAKE2b-256 084c46e4d3f6c59e18663e043d2c9e74de0dd3d06a38260468ef6a8e1f52bbc8

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.10.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8edbbb7d44cfe9e4429c1d77576b82c861641ddd51511e9df905c8660eb3e8fa
MD5 11d3c3272a9824bdc2278fcfdc4a76f9
BLAKE2b-256 abe4536ea698d1d47bce7605af938905b742f7d76a6d2ff5badca18c0a7fd024

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 526e553d12428b6e4be4eb2308afb06ddc6b7b82b2db60fea4d33bb96df0cb05
MD5 a75f81e37bb9f8ead977abb3a6b0e8ff
BLAKE2b-256 cf89f7992bc366d7e4973fefecba436df22ff6401c27295420dddc93b717c342

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b6383535696d2c08e983ffc4394318a8dd646b65f17f0e442527f137720f0b41
MD5 1eb08ed6e1367bf16204dead1c696b65
BLAKE2b-256 4f0b7bdf7cb4abd1f499a543e8440dcd3d90c779e20340372aca2d8efdad9e6c

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jsonschema_rs-0.10.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0aad578c053434a74c06ce87cbed38909e042c7484c8a5028a0daa79fb2a544c
MD5 6b58f7c4dddd23b47ac5c84ae2975dd9
BLAKE2b-256 07deeb207bfee4a04e2f70a91495ec9eb05830672701623967f3b1bf1d784e4a

See more details on using hashes here.

File details

Details for the file jsonschema_rs-0.10.0-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jsonschema_rs-0.10.0-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

Hashes for jsonschema_rs-0.10.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8cf0b4f5693c1bdbcf952b197bbc174cb5ec0df1cecbfabd57c28494619ff8ce
MD5 71c68b21bcee883cc51951fd95174388
BLAKE2b-256 622f834e7288531d0546305c3a2974fbcfc48a9dcf13b72b60886c5bed5ee71b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page