VOOZH about

URL: https://pypi.org/project/jsonschema-path/

⇱ jsonschema-path Β· PyPI


Skip to main content

jsonschema-path 0.5.0

pip install jsonschema-path

Latest release

Released:

JSONSchema Spec with object-oriented paths

Navigation

Verified details

These details have been verified by PyPI
Project links
GitHub Statistics
Maintainers
πŸ‘ Avatar for p1c2u from gravatar.com
p1c2u

Unverified details

These details have not been verified by PyPI
Meta
  • License: Apache Software License (Apache-2.0)
  • Author: Artur Maciag
  • Tags jsonschema , swagger , spec
  • Requires: Python <4.0.0, >=3.10
  • Provides-Extra: requests

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

>>> fromjsonschema_pathimport 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 pathTrue>>> # Concatenate paths with />>> info_path = path / "properties" / "info">>> # Stat keys with implicit dereferencing>>> "properties" in info_pathTrue>>> # 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'}

Identity and equality

Two SchemaPath instances are equal if they have the same parts and point to the same SchemaAccessor. SchemaAccessor identity is per-resource-handle: same wrapped dict (by reference), same base_uri, and same internal resolver instance. In practice:

  • Paths derived from the same accessor compare equal as expected:

    >>> accessor = SchemaAccessor.from_schema(d)>>> SchemaPath(accessor) / "properties" == SchemaPath(accessor) / "properties"True
  • Paths from separate from_dict or from_schema calls do not compare equal even with identical arguments, because each call builds its own accessor:

    >>> SchemaPath.from_dict(d) == SchemaPath.from_dict(d)False
  • SchemaAccessor is hashable, so accessors and paths can be used as set members and dict keys.

This is also why the β€œbuild one accessor, reuse it” pattern below matters: it is both a caching optimisation and the contract you need for path equality to behave the way you expect.

Resolved cache

The resolved-path cache is intended for repeated path lookups and may significantly improve read_value/membership hot paths. When the underlying referencing registry grows (e.g. an external $ref pulls in a new document), cached entries are rebound to the new registry on read instead of being discarded. This relies on registries growing monotonically β€” resources are added, never replaced. Handlers that return drifting content for the same URI violate that assumption; disable caching with resolved_cache_maxsize=0 if you need to defend against it.

This cache is enabled by default (resolved_cache_maxsize=128). You can disable it when creating paths or accessors, for example:

>>> path = SchemaPath.from_dict(d, resolved_cache_maxsize=0)

Build one SchemaAccessor per schema document and reuse it for every SchemaPath you derive from that document. Treat the accessor as the long-lived handle to the resource; treat paths as cheap views over it.

>>> fromjsonschema_pathimport SchemaAccessor, SchemaPath>>> # Construct the accessor once, with caching enabled.>>> accessor = SchemaAccessor.from_schema(d, resolved_cache_maxsize=128)>>> # Derive as many paths as you like from the same accessor.>>> root = SchemaPath(accessor)>>> info = root / "properties" / "info">>> version = info / "properties" / "version">>> # Every path over `accessor` shares the same resolved-ref cache.>>> with version.open() as contents:... ...

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 and resolved cache maxsize via env vars:

export JSONSCHEMA_PATH_BENCH_REPEATS=5
export JSONSCHEMA_PATH_BENCH_WARMUP=1
export JSONSCHEMA_PATH_BENCH_RESOLVED_CACHE_MAXSIZE=64

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

Related projects

  • openapi-core

    Python library that adds client-side and server-side support for the OpenAPI.

  • openapi-spec-validator

    Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger) and OpenAPI 3.0 specification

  • openapi-schema-validator

    Python library that validates schema against the OpenAPI Schema Specification v3.0.

License

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

Project details

Verified details

These details have been verified by PyPI
Project links
GitHub Statistics
Maintainers
πŸ‘ Avatar for p1c2u from gravatar.com
p1c2u

Unverified details

These details have not been verified by PyPI
Meta
  • License: Apache Software License (Apache-2.0)
  • Author: Artur Maciag
  • Tags jsonschema , swagger , spec
  • Requires: Python <4.0.0, >=3.10
  • Provides-Extra: requests

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_path-0.5.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

Filter files by name, interpreter, ABI, and platform.

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

Copy a direct link to the current filters

jsonschema_path-0.5.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonschema_path-0.5.0.tar.gz
Algorithm Hash digest
SHA256 493b156ba895c97602655b620a8456caa2ce08c1aa389f5a7addec065e6e855c
MD5 7837c15f78765ea256ab44cce039d36a
BLAKE2b-256 3979cd02a4df6d9270efdc7d3feefe6edd730b0820c39eeaa107a2faee8322d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonschema_path-0.5.0.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.5.0-py3-none-any.whl.

File metadata

  • Download URL: jsonschema_path-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for jsonschema_path-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2790a070bc7abb08ea3dbe4d340ece4efadf639223001f020c7503229ba068e2
MD5 95681811334f93481becbbeadb72a489
BLAKE2b-256 042c9e69d73c4297508be9e3b64a970ea3971b3eb8db64ffc5802d40bd25981f

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonschema_path-0.5.0-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

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