Skip to main content

Rust/PyO3 accelerator for jsonpath-ng: a native parser with transparent fallback to jsonpath-ng (~500× faster parse).

Project description

pulse-jsonpath-ng

A Rust/PyO3 accelerator for jsonpath-ng — a native parser that is iso-functional with jsonpath_ng and ~500× faster at parsing, with transparent fallback to jsonpath-ng for anything outside its fast path. It's a separate package that depends on jsonpath-ng: it rebuilds jsonpath-ng's own AST and reuses its evaluator, so it never diverges — by construction.

pip install pulse-jsonpath-ng
# was:  from jsonpath_ng import parse
from pulse_jsonpath_ng import parse

expr = parse("items[*].price")     # parsed in Rust, ~500× faster
[m.value for m in expr.find(data)] # .find() is jsonpath_ng's own — identical results

The only change is the import. parse() returns a real jsonpath_ng expression (same classes), so .find(), .full_path, __eq__, and the exceptions all work unchanged.

Performance

jsonpath_ng.parse is the hot spot: it's built on PLY with write_tables=0, so it rebuilds the LALR parse table (and the lexer table) on every single call — ~2.5 ms to parse a 3-segment expression, roughly 300× the cost of the find it precedes. pulse-jsonpath-ng replaces only the parser with a hand-written recursive-descent parser in Rust.

median / parse() speedup
jsonpath_ng.parse ~2.5 ms
pulse_jsonpath_ng.parse ~5 µs ~×500
import statistics, time, jsonpath_ng, pulse_jsonpath_ng
EXPR = "items[*].price"
def bench(parse, reps, rounds=15):
    out = []
    for _ in range(rounds):
        t = time.perf_counter()
        for _ in range(reps): parse(EXPR)
        out.append((time.perf_counter() - t) / reps)
    return statistics.median(out)
r = bench(jsonpath_ng.parse, 200); c = bench(pulse_jsonpath_ng.parse, 20000)
print(f"jsonpath_ng {r*1e6:.0f} us  ->  pulse {c*1e6:.2f} us   (x{r/c:.0f})")

If you already cache compiled expressions you won't see this — but a great deal of code calls jsonpath_ng.parse(...) inline on every request, and that is exactly where the per-call table rebuild hurts.

Why Rust wins here (and why this is not a false friend)

Profiling a parse(): ~100 % of the time is interpreted Python — PLY rebuilding lr_parse_table and the lexer table — with re accounting for ~0.2 % (the lexer regex, built once). Because the bottleneck is interpreted table-construction (not a C-bound kernel), a native parser wins by orders of magnitude. We port only the parser; find stays in jsonpath_ng (reused, so evaluation is iso for free).

What's covered natively (and what falls back)

The Rust fast-path covers the common ./[...] expressions, left-associative:

  • fields a.b.c, wildcard * / a.*, numeric fields a.5, root $, `this`;
  • brackets [0], [-1], [0,2], slices [1:3] / [::2] / [*], field brackets ['a','b'];
  • quoted fields 'a.b', dotted-bracket equivalence a.[0]a[0].

Everything else is transparently delegated to jsonpath_ng: descendants .., |/& (union/ intersect), where/wherenot, parent, parentheses, named operators other than this, unicode identifiers, and any invalid or ambiguous input (jsonpath_ng then returns the correct tree or raises the correct JsonPathParserError/JsonPathLexerError). The fast-path is a strict subset — it never accepts something it can't reproduce exactly.

Iso-functionality

The Rust parser rebuilds the same jsonpath_ng AST classes, so iso is verifiable two ways: the parsed tree is structurally == to jsonpath_ng.parse(expr), and .find() (jsonpath_ng's own) returns identical values and paths. Proven by a differential oracle over a curated corpus plus adversarial fuzzing of random expressions — tree equality, .find() parity, and exception-type parity for invalid input. The pure-jsonpath_ng fallback path is verified iso too (PULSE_FORCE_FALLBACK=1).

Wheels

abi3 wheels (Python ≥ 3.11) for Linux (x86_64/aarch64, manylinux + musllinux), macOS (Apple Silicon), and Windows; sdist elsewhere (builds the Rust core via maturin).

License

Apache-2.0 (same as jsonpath-ng).

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

pulse_jsonpath_ng-0.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distributions

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

pulse_jsonpath_ng-0.1.0-cp311-abi3-win_amd64.whl (103.1 kB view details)

Uploaded CPython 3.11+Windows x86-64

pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (215.3 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (214.0 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

pulse_jsonpath_ng-0.1.0-cp311-abi3-macosx_11_0_arm64.whl (198.4 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file pulse_jsonpath_ng-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for pulse_jsonpath_ng-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3c41900b98106450960c99ff394dd78815411d425b5e60b49b2488e1f9f6c8b
MD5 34bdf77919aa1def4cafcbfcfcc0c0d4
BLAKE2b-256 0e13d77475b498b26a6315384cd2fd00d360f2082c289b1b2dd5fe5af6bf817f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_jsonpath_ng-0.1.0.tar.gz:

Publisher: release.yml on AstekGroup/pulse-jsonpath-ng

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

File details

Details for the file pulse_jsonpath_ng-0.1.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pulse_jsonpath_ng-0.1.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 02b64d8bf6bb4ab4b6deb3ac4b8c3d16c46ea444439354b412606a904e17ae8c
MD5 a16b21f808c58eb0ed921e68c209c6ed
BLAKE2b-256 76fc2b10009e85487fec71cf6482e4401ee279a01ed09eeb913a0f6bfc86e5e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_jsonpath_ng-0.1.0-cp311-abi3-win_amd64.whl:

Publisher: release.yml on AstekGroup/pulse-jsonpath-ng

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

File details

Details for the file pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7945363ccf583f437542cd8a95acc5f47d80e8d6720824675acf87f268e8d82c
MD5 3cf4e5da3d0076ed6430524db653044b
BLAKE2b-256 4ad595a306c8bd4873472e10ec72b33846e88496b6c5af418a047563fc22a7a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on AstekGroup/pulse-jsonpath-ng

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

File details

Details for the file pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 38ea0651b7c35af680ae731f6a5d21a75190f8bec5836815f019586cc5831848
MD5 0fdf47de41d284c285dde4b8a032d59c
BLAKE2b-256 32a73dbe0663bb6f2ab4b503843918a6cf00d3221d5aefd05836d4645c337961

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_jsonpath_ng-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on AstekGroup/pulse-jsonpath-ng

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

File details

Details for the file pulse_jsonpath_ng-0.1.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pulse_jsonpath_ng-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da86d63b520da6510692e6509b87389f917554484e8f11a7352e779e3e7586f6
MD5 2594d1de7db62013eed440d2a4d7b45e
BLAKE2b-256 0124895c928be434b29e9dc67118ae1b39a92b6621db09d698c57efbcc9ef4f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_jsonpath_ng-0.1.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on AstekGroup/pulse-jsonpath-ng

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