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

This version

0.9.0

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.9.0.tar.gz (64.2 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.9.0-cp39-cp39-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9Windows x86-64

jsonschema_rs-0.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.9.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.9.0-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

jsonschema_rs-0.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

jsonschema_rs-0.9.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.9.0-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

jsonschema_rs-0.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.9.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.9.0-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

jsonschema_rs-0.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jsonschema_rs-0.9.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.9.0.tar.gz.

File metadata

  • Download URL: jsonschema_rs-0.9.0.tar.gz
  • Upload date:
  • Size: 64.2 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.10

File hashes

Hashes for jsonschema_rs-0.9.0.tar.gz
Algorithm Hash digest
SHA256 1c5292ba809814e742b309f1d5dd238814edf996383dc23f80aad2383fd788b4
MD5 dfd48ac77a7195fd91b85815083d366b
BLAKE2b-256 fccbeb0f28f55eeb402b9f1426ad8565ada4247de8d14c3e87d3f9cd9b0b3939

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 14eabac0a173f319440e23c5f698e23ab322c1083db03c5ece38c86e1165840f
MD5 6badacaaa98c8bc8cf254888b36a9c9d
BLAKE2b-256 b77b0fdce6feeb6d1413a2a2fb263d2ed4c0e064286cca7a978e19daa7e1334d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa5656e2b10b7c79547ecc181af19ffc4af442fb3adacc0c5371e8e46232b9d1
MD5 216aa7bf170989207af63392fc9b75c9
BLAKE2b-256 a836cf054104c234adcf02b7f9fa46a9e042459e7e3496c3ea074fe5295ff6e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 237b95e65c3608f2c7771cfe204dff09436df508f97f08d1e636aa003d01afa1
MD5 7dd1eb7069751b67de383dd4fd35cde7
BLAKE2b-256 91ba292da2c7c7ef4f2c23f43ef8e8501110eb99e6eccca7b692f8a7fd3ab48a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d68f94a9f7f2e35ea3888d7d7f4c84730cf5ba2164d6664ef72ed8543c8c5f4f
MD5 951b862519257fd09a83604411fc44ee
BLAKE2b-256 92c230267ac123e8a3fea8df59cde88e58de1ad1ab60a30eadfdb63001350831

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99f1d3784fe71d2fd848dff8f6cbb0d5bca5c2960002bc0136e706d130cd319c
MD5 389faac2dbb8a6010fe756628298908f
BLAKE2b-256 2dfcfbe3f67ba4c902f73fc6371c536230e194cccd02d83b1512e56e67d1f71d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5efc8cfa55b37c48bf45befc912f0f4c87c067a9d4646d9549dae88e0a9299ff
MD5 7ed1bad21978c9bb6a5eebb7f881b72b
BLAKE2b-256 38b11db16f572e377d72065f38a8f6f6a64b157b8bb4b8abe68d21656de467a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 d840d7e685af7e8d037ba0cb6f55602853d6bf11d89f22e08ad449f9ff8c56aa
MD5 de310afa725f29bb1ffc1515373f316b
BLAKE2b-256 ef7408ddbb1f5e2cfab317be2fa048c2d0371a3a1f5981d25f77261affbbc840

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a10f3fe0cb050576d0e0601118156e80b10f0a0ce9771a185d5540fee2948681
MD5 f34255b8d306880677a4b1ffbd64f384
BLAKE2b-256 9be2e93ae18a92c8b7ad0f54f26e46cdcd99b3e5c4f26b8a058a9e7180558a70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 842c781107c577fc80847c0371d0f4e257c0667b8041abfe9ee3e3d525cf8db6
MD5 d7518908bce7a8d4f1c5a765c1cc121e
BLAKE2b-256 6d28eeeeb28024c3800f42c9d332b00a4170f3db3f6c82db6ecb38037fbbfa3b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 20aa473dde2c7e192becb1645aa4b09f666e12b17dbfe9a869cf712f30bd30df
MD5 1dcc34c44c109766c76c447ef57e8ced
BLAKE2b-256 ea272247234c2e497283a75fe6c926992c6e7ad5d1660bdefc8c5dc81d93e461

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jsonschema_rs-0.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 20a58f2b3d4754a0b8b5f42ae5508737b20fc50d0619cd83e8ea20207f997803
MD5 c69a147b39429656d076c28dda01140a
BLAKE2b-256 1c9e0ae33f0093b299ef785558066319aca48ed53b22a3d16cb837b4684da43e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonschema_rs-0.9.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.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for jsonschema_rs-0.9.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 205ee53dd17bc636a5bb78c8ebdd89ba3affb49fc5b0a59955f992e74d8047b4
MD5 db4b4ffee30812120805f2ff311062df
BLAKE2b-256 b8bb38d268df3dbdd5a54c610933c9c43ba2cbc98f1f347610c2ff17b27d20cb

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