Skip to main content

A conservative JSON Schema subschema prover

Project description

subschema

subschema is a conservative prover for JSON Schema subschema checks.

For JSON Schemas lhs and rhs, lhs <: rhs means every JSON instance that validates against lhs also validates against rhs.

The PyPI package, Python import package, and CLI command are named subschema.

Install

pip install subschema

For local development:

uv sync --locked --group dev
uv run pytest -q
uv run ruff check .

CLI

subschema lhs.json rhs.json

The command prints whether lhs.json <: rhs.json.

Finite expensive proof products can be enabled explicitly:

subschema --endeavor --max-work 20000 --timeout-ms 3000 lhs.json rhs.json

max_work and timeout_ms are only accepted with --endeavor. A value of -1 means unlimited for that control.

Python API

from subschema import Dialect, is_subschema

lhs = {"type": "integer"}
rhs = {"type": "number"}

print(is_subschema(lhs, rhs, dialect=Dialect.DRAFT202012))

Available public entrypoints:

  • is_subschema(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)
  • is_equivalent(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)
  • meet_schemas(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)
  • join_schemas(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)
  • canonicalize_schema(schema, *, dialect=None)

Dialects

Draft 2020-12 is the default dialect for calls without an explicit dialect or $schema declaration. Older dialects can be selected by passing dialect=... or by using a $schema declaration.

Supported dialects:

  • Draft 4
  • Draft 6
  • Draft 7
  • Draft 2019-09
  • Draft 2020-12

The prover is intentionally conservative. Unsupported, unbounded, recursive, or exhausted proof fragments are reported instead of being silently approximated.

Acknowledgement

This project is a rewrite based on IBM's jsonsubschema project and may retain portions of its source code. Credit to IBM and contributors.

License

Apache License 2.0. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subschema-0.0.1.tar.gz (191.5 kB view details)

Uploaded Source

Built Distribution

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

subschema-0.0.1-py3-none-any.whl (155.3 kB view details)

Uploaded Python 3

File details

Details for the file subschema-0.0.1.tar.gz.

File metadata

  • Download URL: subschema-0.0.1.tar.gz
  • Upload date:
  • Size: 191.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for subschema-0.0.1.tar.gz
Algorithm Hash digest
SHA256 039f5bb4a67489dc99be97d2263b24a09ceebb92520a10d7d6df98a0f338e360
MD5 06b29d580401799efaa1cc2b450d8915
BLAKE2b-256 b97560a448626a08ec275954d2fd80e39ce1bee072dc5f142c5ac8e9ba16603a

See more details on using hashes here.

File details

Details for the file subschema-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: subschema-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 155.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for subschema-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b8c52f5422f905262ba276eac05a1df0f316a1c2c0ca9d13fe900d56936ae3f
MD5 3dfe130161934a33e48b5a95d107e7af
BLAKE2b-256 2c5e9422cf41694ba38f9ce2136c944d6edbd20ed41bfb7b599b79cf038c6979

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