Skip to main content

JSONSchema Spec with object-oriented paths

Project description

https://img.shields.io/pypi/v/jsonschema-path.svg https://travis-ci.org/p1c2u/jsonschema-path.svg?branch=master https://img.shields.io/codecov/c/github/p1c2u/jsonschema-path/master.svg?style=flat https://img.shields.io/pypi/pyversions/jsonschema-path.svg https://img.shields.io/pypi/format/jsonschema-path.svg https://img.shields.io/pypi/status/jsonschema-path.svg

About

Object-oriented JSONSchema

Key features

  • Traverse schema like paths

  • Access schema on demand with separate dereferencing accessor layer

Installation

pip install jsonschema-path

Alternatively you can download the code and install from the repository:

pip install -e git+https://github.com/p1c2u/jsonschema-path.git#egg=jsonschema_path

Usage

>>> from jsonschema_path import SchemaPath

>>> d = {
...     "properties": {
...        "info": {
...            "$ref": "#/$defs/Info",
...        },
...     },
...     "$defs": {
...         "Info": {
...             "properties": {
...                 "title": {
...                     "$ref": "http://example.com",
...                 },
...                 "version": {
...                     "type": "string",
...                     "default": "1.0",
...                 },
...             },
...         },
...     },
... }

>>> path = SchemaPath.from_dict(d)

>>> # Stat keys
>>> "properties" in path
True

>>> # Concatenate paths with /
>>> info_path = path / "properties" / "info"

>>> # Stat keys with implicit dereferencing
>>> "properties" in info_path
True

>>> # Concatenate paths with implicit dereferencing
>>> version_path = info_path / "properties" / "version"

>>> # Open content with implicit dereferencing
>>> with version_path.open() as contents:
...     print(contents)
{'type': 'string', 'default': '1.0'}

Benchmarks

Benchmarks mirror the lightweight (dependency-free) JSON output format used in pathable.

Run locally with Poetry:

poetry run python -m tests.benchmarks.bench_parse --output reports/bench-parse.json
poetry run python -m tests.benchmarks.bench_lookup --output reports/bench-lookup.json

For a quick smoke run:

poetry run python -m tests.benchmarks.bench_parse --output reports/bench-parse.quick.json --quick
poetry run python -m tests.benchmarks.bench_lookup --output reports/bench-lookup.quick.json --quick

You can also control repeats/warmup via env vars:

export JSONSCHEMA_PATH_BENCH_REPEATS=5
export JSONSCHEMA_PATH_BENCH_WARMUP=1

Compare two results:

poetry run python -m tests.benchmarks.compare_results \
   --baseline reports/bench-lookup-master.json \
   --candidate reports/bench-lookup.json \
   --tolerance 0.20

License

Copyright (c) 2017-2025, Artur Maciag, All rights reserved. Apache-2.0

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

jsonschema_path-0.4.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

jsonschema_path-0.4.2-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema_path-0.4.2.tar.gz.

File metadata

  • Download URL: jsonschema_path-0.4.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jsonschema_path-0.4.2.tar.gz
Algorithm Hash digest
SHA256 5f5ff183150030ea24bb51cf1ddac9bf5dbf030272e2792a7ffe8262f7eea2a5
MD5 2d7f894864c8f1b6999860aa9a8a3bfb
BLAKE2b-256 b3da1ebeb1c0ff579c330e200e8b06e6200653e3d0758136d8bd86762d63e7de

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonschema_path-0.4.2.tar.gz:

Publisher: python-publish.yml on p1c2u/jsonschema-path

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jsonschema_path-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema_path-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c3d88e727cc4f1a88e51dbbed4211dbcd815d27799d2685efd904435c3d39e7
MD5 7fa2464df2432d1bec6692997ae499f6
BLAKE2b-256 e81096f8fe82137979fcd1e46fff243ce7d80cd03b9e1cee8f22476ce780f38c

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonschema_path-0.4.2-py3-none-any.whl:

Publisher: python-publish.yml on p1c2u/jsonschema-path

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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