pjmespath 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pjmespath-0.1.0/.github/workflows/ci.yml +136 -0
- pjmespath-0.1.0/.gitignore +12 -0
- pjmespath-0.1.0/Cargo.lock +133 -0
- pjmespath-0.1.0/Cargo.toml +19 -0
- pjmespath-0.1.0/LICENSE +25 -0
- pjmespath-0.1.0/PKG-INFO +70 -0
- pjmespath-0.1.0/README.md +43 -0
- pjmespath-0.1.0/SECURITY.md +11 -0
- pjmespath-0.1.0/benchmarks/bench.py +91 -0
- pjmespath-0.1.0/pyproject.toml +58 -0
- pjmespath-0.1.0/python/pjmespath/__init__.py +19 -0
- pjmespath-0.1.0/python/pjmespath/__init__.pyi +19 -0
- pjmespath-0.1.0/python/pjmespath/_pjmespath.pyi +35 -0
- pjmespath-0.1.0/python/pjmespath/ast.py +91 -0
- pjmespath-0.1.0/python/pjmespath/compat.py +27 -0
- pjmespath-0.1.0/python/pjmespath/exceptions.py +130 -0
- pjmespath-0.1.0/python/pjmespath/functions.py +327 -0
- pjmespath-0.1.0/python/pjmespath/parser.py +18 -0
- pjmespath-0.1.0/python/pjmespath/py.typed +0 -0
- pjmespath-0.1.0/python/pjmespath/visitor.py +54 -0
- pjmespath-0.1.0/src/ast.rs +249 -0
- pjmespath-0.1.0/src/errors.rs +105 -0
- pjmespath-0.1.0/src/eval.rs +822 -0
- pjmespath-0.1.0/src/json.rs +395 -0
- pjmespath-0.1.0/src/lexer.rs +563 -0
- pjmespath-0.1.0/src/lib.rs +176 -0
- pjmespath-0.1.0/src/parser.rs +532 -0
- pjmespath-0.1.0/src/simd.rs +621 -0
- pjmespath-0.1.0/tests/test_adversarial.py +96 -0
- pjmespath-0.1.0/tests/test_concurrency_and_leaks.py +56 -0
- pjmespath-0.1.0/tests/test_differential.py +84 -0
- pjmespath-0.1.0/tests/test_ecosystem.py +44 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint-and-test-rust:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
18
|
+
with:
|
|
19
|
+
components: rustfmt, clippy
|
|
20
|
+
- uses: Swatinem/rust-cache@v2
|
|
21
|
+
- run: cargo fmt --check
|
|
22
|
+
- run: cargo clippy --all-targets -- -D warnings
|
|
23
|
+
- run: cargo test --lib
|
|
24
|
+
|
|
25
|
+
build-wheels:
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
matrix:
|
|
29
|
+
include:
|
|
30
|
+
- os: ubuntu-latest
|
|
31
|
+
target: x86_64
|
|
32
|
+
args: --release --compatibility manylinux2014
|
|
33
|
+
run_tests: true
|
|
34
|
+
- os: ubuntu-latest
|
|
35
|
+
target: musl-x86_64
|
|
36
|
+
args: --release --compatibility musllinux_1_2
|
|
37
|
+
run_tests: false
|
|
38
|
+
- os: ubuntu-24.04-arm
|
|
39
|
+
target: aarch64
|
|
40
|
+
args: --release --compatibility manylinux2014
|
|
41
|
+
run_tests: true
|
|
42
|
+
- os: ubuntu-24.04-arm
|
|
43
|
+
target: musl-aarch64
|
|
44
|
+
args: --release --compatibility musllinux_1_2
|
|
45
|
+
run_tests: false
|
|
46
|
+
- os: macos-15
|
|
47
|
+
target: aarch64
|
|
48
|
+
args: --release
|
|
49
|
+
run_tests: true
|
|
50
|
+
- os: macos-15
|
|
51
|
+
target: x86_64
|
|
52
|
+
args: --release --target x86_64-apple-darwin
|
|
53
|
+
run_tests: false
|
|
54
|
+
- os: windows-latest
|
|
55
|
+
target: x64
|
|
56
|
+
args: --release
|
|
57
|
+
run_tests: true
|
|
58
|
+
runs-on: ${{ matrix.os }}
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v4
|
|
61
|
+
- uses: actions/setup-python@v5
|
|
62
|
+
with:
|
|
63
|
+
python-version: "3.12"
|
|
64
|
+
- uses: PyO3/maturin-action@v1
|
|
65
|
+
with:
|
|
66
|
+
command: build
|
|
67
|
+
args: ${{ matrix.args }} -o dist
|
|
68
|
+
manylinux: auto
|
|
69
|
+
- name: Check wheel metadata
|
|
70
|
+
shell: bash
|
|
71
|
+
run: |
|
|
72
|
+
python -m pip install --upgrade pip twine
|
|
73
|
+
twine check dist/*.whl
|
|
74
|
+
- name: Install and test abi3 wheel
|
|
75
|
+
if: matrix.run_tests
|
|
76
|
+
shell: bash
|
|
77
|
+
run: |
|
|
78
|
+
python -m pip install pytest hypothesis jmespath mypy ruff abi3audit
|
|
79
|
+
python -m pip install dist/*.whl
|
|
80
|
+
pytest -v
|
|
81
|
+
- name: Static typing, stubtest, and abi3audit (Linux)
|
|
82
|
+
if: runner.os == 'Linux' && matrix.run_tests
|
|
83
|
+
run: |
|
|
84
|
+
ruff format --check python tests
|
|
85
|
+
ruff check python tests
|
|
86
|
+
mypy --strict python/pjmespath
|
|
87
|
+
stubtest --ignore-disjoint-base pjmespath
|
|
88
|
+
abi3audit --strict dist/*.whl
|
|
89
|
+
- uses: actions/upload-artifact@v4
|
|
90
|
+
with:
|
|
91
|
+
name: wheels-${{ matrix.os }}-${{ matrix.target }}
|
|
92
|
+
path: dist/*.whl
|
|
93
|
+
|
|
94
|
+
build-sdist:
|
|
95
|
+
runs-on: ubuntu-latest
|
|
96
|
+
steps:
|
|
97
|
+
- uses: actions/checkout@v4
|
|
98
|
+
- uses: PyO3/maturin-action@v1
|
|
99
|
+
with:
|
|
100
|
+
command: sdist
|
|
101
|
+
args: -o dist
|
|
102
|
+
- uses: actions/upload-artifact@v4
|
|
103
|
+
with:
|
|
104
|
+
name: sdist
|
|
105
|
+
path: dist/*.tar.gz
|
|
106
|
+
|
|
107
|
+
publish:
|
|
108
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
109
|
+
needs: [lint-and-test-rust, build-wheels, build-sdist]
|
|
110
|
+
runs-on: ubuntu-latest
|
|
111
|
+
environment: pypi
|
|
112
|
+
permissions:
|
|
113
|
+
id-token: write
|
|
114
|
+
attestations: write
|
|
115
|
+
contents: write
|
|
116
|
+
steps:
|
|
117
|
+
- uses: actions/download-artifact@v4
|
|
118
|
+
with:
|
|
119
|
+
path: dist
|
|
120
|
+
merge-multiple: true
|
|
121
|
+
- name: Attest build provenance (SLSA)
|
|
122
|
+
uses: actions/attest-build-provenance@v2
|
|
123
|
+
with:
|
|
124
|
+
subject-path: "dist/*"
|
|
125
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
126
|
+
with:
|
|
127
|
+
packages-dir: dist/
|
|
128
|
+
- name: Generate SHA-256 checksums
|
|
129
|
+
run: (cd dist && sha256sum *.whl *.tar.gz) > SHA256SUMS.txt
|
|
130
|
+
- name: Create GitHub Release
|
|
131
|
+
uses: softprops/action-gh-release@v2
|
|
132
|
+
with:
|
|
133
|
+
generate_release_notes: true
|
|
134
|
+
files: |
|
|
135
|
+
dist/*
|
|
136
|
+
SHA256SUMS.txt
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "heck"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "libc"
|
|
13
|
+
version = "0.2.191"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "once_cell"
|
|
19
|
+
version = "1.21.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "pjmespath"
|
|
25
|
+
version = "0.1.0"
|
|
26
|
+
dependencies = [
|
|
27
|
+
"pyo3",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[[package]]
|
|
31
|
+
name = "portable-atomic"
|
|
32
|
+
version = "1.15.0"
|
|
33
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
34
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
35
|
+
|
|
36
|
+
[[package]]
|
|
37
|
+
name = "proc-macro2"
|
|
38
|
+
version = "1.0.107"
|
|
39
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
40
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
41
|
+
dependencies = [
|
|
42
|
+
"unicode-ident",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[[package]]
|
|
46
|
+
name = "pyo3"
|
|
47
|
+
version = "0.28.3"
|
|
48
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
49
|
+
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
|
|
50
|
+
dependencies = [
|
|
51
|
+
"libc",
|
|
52
|
+
"once_cell",
|
|
53
|
+
"portable-atomic",
|
|
54
|
+
"pyo3-build-config",
|
|
55
|
+
"pyo3-ffi",
|
|
56
|
+
"pyo3-macros",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[[package]]
|
|
60
|
+
name = "pyo3-build-config"
|
|
61
|
+
version = "0.28.3"
|
|
62
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
63
|
+
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
|
|
64
|
+
dependencies = [
|
|
65
|
+
"target-lexicon",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[[package]]
|
|
69
|
+
name = "pyo3-ffi"
|
|
70
|
+
version = "0.28.3"
|
|
71
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
72
|
+
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
|
|
73
|
+
dependencies = [
|
|
74
|
+
"libc",
|
|
75
|
+
"pyo3-build-config",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[[package]]
|
|
79
|
+
name = "pyo3-macros"
|
|
80
|
+
version = "0.28.3"
|
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
82
|
+
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
|
|
83
|
+
dependencies = [
|
|
84
|
+
"proc-macro2",
|
|
85
|
+
"pyo3-macros-backend",
|
|
86
|
+
"quote",
|
|
87
|
+
"syn",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
[[package]]
|
|
91
|
+
name = "pyo3-macros-backend"
|
|
92
|
+
version = "0.28.3"
|
|
93
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
94
|
+
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
|
|
95
|
+
dependencies = [
|
|
96
|
+
"heck",
|
|
97
|
+
"proc-macro2",
|
|
98
|
+
"pyo3-build-config",
|
|
99
|
+
"quote",
|
|
100
|
+
"syn",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "quote"
|
|
105
|
+
version = "1.0.47"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"proc-macro2",
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[[package]]
|
|
113
|
+
name = "syn"
|
|
114
|
+
version = "2.0.119"
|
|
115
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
116
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
117
|
+
dependencies = [
|
|
118
|
+
"proc-macro2",
|
|
119
|
+
"quote",
|
|
120
|
+
"unicode-ident",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
[[package]]
|
|
124
|
+
name = "target-lexicon"
|
|
125
|
+
version = "0.13.6"
|
|
126
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
127
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
128
|
+
|
|
129
|
+
[[package]]
|
|
130
|
+
name = "unicode-ident"
|
|
131
|
+
version = "1.0.27"
|
|
132
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
133
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "pjmespath"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
description = "Fast JMESPath JSON query engine for Python"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
name = "_pjmespath"
|
|
11
|
+
crate-type = ["cdylib", "rlib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
pyo3 = { version = "0.28", features = ["abi3-py39"] }
|
|
15
|
+
|
|
16
|
+
[profile.release]
|
|
17
|
+
lto = "thin"
|
|
18
|
+
codegen-units = 1
|
|
19
|
+
opt-level = 3
|
pjmespath-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, gatewaytofredom
|
|
4
|
+
|
|
5
|
+
Portions of the Python compatibility layer and exception definitions are
|
|
6
|
+
adapted from jmespath.py:
|
|
7
|
+
Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
pjmespath-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pjmespath
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Rust
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Summary: Fast JMESPath JSON query engine for Python
|
|
20
|
+
Keywords: jmespath,json,query,search,rust
|
|
21
|
+
License-Expression: MIT
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
24
|
+
Project-URL: Homepage, https://github.com/gatewaytofredom/pjmespath
|
|
25
|
+
Project-URL: Repository, https://github.com/gatewaytofredom/pjmespath
|
|
26
|
+
|
|
27
|
+
# pjmespath
|
|
28
|
+
|
|
29
|
+
[](https://github.com/gatewaytofredom/pjmespath/actions/workflows/ci.yml)
|
|
30
|
+
[](https://pypi.org/project/pjmespath/)
|
|
31
|
+
[](https://pypi.org/project/pjmespath/)
|
|
32
|
+
[](https://github.com/gatewaytofredom/pjmespath/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
Fast JMESPath JSON query engine for Python — a drop-in replacement for `jmespath` that runs **7–10× faster**.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install pjmespath
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Prebuilt wheels are included for Linux, macOS, and Windows (Python 3.9+, no Rust toolchain needed).
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import pjmespath
|
|
48
|
+
|
|
49
|
+
data = {"people": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]}
|
|
50
|
+
names = pjmespath.search("people[?age > `26`].name", data)
|
|
51
|
+
# ['Alice']
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Performance
|
|
55
|
+
|
|
56
|
+
| Workload | `jmespath` | `pjmespath` (x86-64) | `pjmespath` (Apple M4) |
|
|
57
|
+
|---|---:|---:|---:|
|
|
58
|
+
| Small (`search`) | 2.38 µs | 0.23 µs (10.25×) | 0.19 µs (7.16×) |
|
|
59
|
+
| Medium AWS (`search`) | 473.23 µs | 59.31 µs (7.98×) | 41.20 µs (7.96×) |
|
|
60
|
+
| Large 1k (`search`) | 1747.77 µs | 203.99 µs (8.57×) | 144.29 µs (8.16×) |
|
|
61
|
+
|
|
62
|
+
## Under the hood
|
|
63
|
+
|
|
64
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
65
|
+
- Compact `cp39-abi3` wheel with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
|
70
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# pjmespath
|
|
2
|
+
|
|
3
|
+
[](https://github.com/gatewaytofredom/pjmespath/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/pjmespath/)
|
|
5
|
+
[](https://pypi.org/project/pjmespath/)
|
|
6
|
+
[](https://github.com/gatewaytofredom/pjmespath/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Fast JMESPath JSON query engine for Python — a drop-in replacement for `jmespath` that runs **7–10× faster**.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install pjmespath
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Prebuilt wheels are included for Linux, macOS, and Windows (Python 3.9+, no Rust toolchain needed).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import pjmespath
|
|
22
|
+
|
|
23
|
+
data = {"people": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]}
|
|
24
|
+
names = pjmespath.search("people[?age > `26`].name", data)
|
|
25
|
+
# ['Alice']
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Performance
|
|
29
|
+
|
|
30
|
+
| Workload | `jmespath` | `pjmespath` (x86-64) | `pjmespath` (Apple M4) |
|
|
31
|
+
|---|---:|---:|---:|
|
|
32
|
+
| Small (`search`) | 2.38 µs | 0.23 µs (10.25×) | 0.19 µs (7.16×) |
|
|
33
|
+
| Medium AWS (`search`) | 473.23 µs | 59.31 µs (7.98×) | 41.20 µs (7.96×) |
|
|
34
|
+
| Large 1k (`search`) | 1747.77 µs | 203.99 µs (8.57×) | 144.29 µs (8.16×) |
|
|
35
|
+
|
|
36
|
+
## Under the hood
|
|
37
|
+
|
|
38
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
39
|
+
- Compact `cp39-abi3` wheel with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
Please report security vulnerabilities privately using GitHub's **Private Vulnerability Reporting** feature on the **Security** tab of this repository (or email `gateway@laindex.net`).
|
|
6
|
+
|
|
7
|
+
Please include:
|
|
8
|
+
- A minimal reproducer (input bytes/string and affected version)
|
|
9
|
+
- Expected vs. observed behavior (e.g., crash, quadratic CPU / ReDoS, memory issue)
|
|
10
|
+
|
|
11
|
+
We aim to acknowledge reports within 48 hours and ship a verified fix promptly.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import pjmespath
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
import jmespath
|
|
7
|
+
except ImportError:
|
|
8
|
+
jmespath = None # type: ignore[assignment]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
SMALL_DATA = {"foo": {"bar": {"baz": "value"}}}
|
|
12
|
+
SMALL_EXPR = "foo.bar.baz"
|
|
13
|
+
|
|
14
|
+
MEDIUM_DATA = {
|
|
15
|
+
"Reservations": [
|
|
16
|
+
{
|
|
17
|
+
"ReservationId": f"r-{i}",
|
|
18
|
+
"Instances": [
|
|
19
|
+
{
|
|
20
|
+
"InstanceId": f"i-{i}-{j}",
|
|
21
|
+
"InstanceType": "t3.micro" if j % 2 == 0 else "m5.large",
|
|
22
|
+
"State": {"Name": "running" if (i + j) % 3 != 0 else "stopped"},
|
|
23
|
+
"Tags": [{"Key": "Name", "Value": f"node-{i}-{j}"}],
|
|
24
|
+
}
|
|
25
|
+
for j in range(10)
|
|
26
|
+
],
|
|
27
|
+
}
|
|
28
|
+
for i in range(20)
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
MEDIUM_EXPR = "Reservations[].Instances[?State.Name=='running'].{id: InstanceId, type: InstanceType}[]"
|
|
32
|
+
|
|
33
|
+
LARGE_DATA = {
|
|
34
|
+
"items": [
|
|
35
|
+
{
|
|
36
|
+
"id": i,
|
|
37
|
+
"name": f"service_identifier_{i}_prod_us_east_1",
|
|
38
|
+
"score": (i * 17) % 100,
|
|
39
|
+
"active": i % 2 == 0,
|
|
40
|
+
"meta": {"region": "us-east-1" if i % 2 == 0 else "eu-west-1", "tier": i % 5},
|
|
41
|
+
}
|
|
42
|
+
for i in range(1000)
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
LARGE_EXPR = "sort_by(items[?active && score >= `50`], &score)[*].{id: id, name: name, region: meta.region}"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def bench(fn, iters: int) -> float:
|
|
49
|
+
for _ in range(min(50, iters // 10)):
|
|
50
|
+
fn()
|
|
51
|
+
t0 = time.perf_counter()
|
|
52
|
+
for _ in range(iters):
|
|
53
|
+
fn()
|
|
54
|
+
t1 = time.perf_counter()
|
|
55
|
+
return ((t1 - t0) / iters) * 1e6
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def main() -> None:
|
|
59
|
+
print(f"{'Workload':<24} {'jmespath (us)':>14} {'pjmespath (us)':>15} {'Speedup':>10}")
|
|
60
|
+
print("-" * 67)
|
|
61
|
+
cases = [
|
|
62
|
+
("Small (search)", SMALL_EXPR, SMALL_DATA, 10_000, False),
|
|
63
|
+
("Small (compiled)", SMALL_EXPR, SMALL_DATA, 20_000, True),
|
|
64
|
+
("Medium AWS (search)", MEDIUM_EXPR, MEDIUM_DATA, 1_000, False),
|
|
65
|
+
("Medium AWS (compiled)", MEDIUM_EXPR, MEDIUM_DATA, 2_000, True),
|
|
66
|
+
("Large 1k (search)", LARGE_EXPR, LARGE_DATA, 300, False),
|
|
67
|
+
("Large 1k (compiled)", LARGE_EXPR, LARGE_DATA, 500, True),
|
|
68
|
+
]
|
|
69
|
+
for label, expr, data, iters, compiled in cases:
|
|
70
|
+
if compiled:
|
|
71
|
+
our_c = pjmespath.compile(expr)
|
|
72
|
+
our_us = bench(lambda: our_c.search(data), iters)
|
|
73
|
+
if jmespath is not None:
|
|
74
|
+
ref_c = jmespath.compile(expr)
|
|
75
|
+
ref_us = bench(lambda: ref_c.search(data), iters)
|
|
76
|
+
else:
|
|
77
|
+
ref_us = 0.0
|
|
78
|
+
else:
|
|
79
|
+
our_us = bench(lambda: pjmespath.search(expr, data), iters)
|
|
80
|
+
if jmespath is not None:
|
|
81
|
+
ref_us = bench(lambda: jmespath.search(expr, data), iters)
|
|
82
|
+
else:
|
|
83
|
+
ref_us = 0.0
|
|
84
|
+
if jmespath is not None and our_us > 0:
|
|
85
|
+
print(f"{label:<24} {ref_us:>14.2f} {our_us:>15.2f} {ref_us / our_us:>9.2f}x")
|
|
86
|
+
else:
|
|
87
|
+
print(f"{label:<24} {'N/A':>14} {our_us:>15.2f} {'N/A':>10}")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if __name__ == "__main__":
|
|
91
|
+
main()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.7,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pjmespath"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Fast JMESPath JSON query engine for Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = [
|
|
13
|
+
"jmespath",
|
|
14
|
+
"json",
|
|
15
|
+
"query",
|
|
16
|
+
"search",
|
|
17
|
+
"rust",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
|
+
"Programming Language :: Rust",
|
|
32
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
|
+
"Typing :: Typed",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/gatewaytofredom/pjmespath"
|
|
38
|
+
Repository = "https://github.com/gatewaytofredom/pjmespath"
|
|
39
|
+
|
|
40
|
+
[tool.maturin]
|
|
41
|
+
python-source = "python"
|
|
42
|
+
module-name = "pjmespath._pjmespath"
|
|
43
|
+
features = ["pyo3/extension-module"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff]
|
|
46
|
+
line-length = 120
|
|
47
|
+
target-version = "py39"
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
51
|
+
|
|
52
|
+
[tool.mypy]
|
|
53
|
+
python_version = "3.10"
|
|
54
|
+
strict = true
|
|
55
|
+
warn_unused_ignores = true
|
|
56
|
+
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from pjmespath import ast, exceptions, functions, parser, visitor
|
|
2
|
+
from pjmespath._pjmespath import ParsedResult, compile, purge, search
|
|
3
|
+
from pjmespath.visitor import Options
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"Options",
|
|
9
|
+
"ParsedResult",
|
|
10
|
+
"__version__",
|
|
11
|
+
"ast",
|
|
12
|
+
"compile",
|
|
13
|
+
"exceptions",
|
|
14
|
+
"functions",
|
|
15
|
+
"parser",
|
|
16
|
+
"purge",
|
|
17
|
+
"search",
|
|
18
|
+
"visitor",
|
|
19
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from pjmespath import ast, exceptions, functions, parser, visitor
|
|
2
|
+
from pjmespath._pjmespath import ParsedResult, compile, purge, search
|
|
3
|
+
from pjmespath.visitor import Options
|
|
4
|
+
|
|
5
|
+
__version__: str
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"Options",
|
|
9
|
+
"ParsedResult",
|
|
10
|
+
"__version__",
|
|
11
|
+
"ast",
|
|
12
|
+
"compile",
|
|
13
|
+
"exceptions",
|
|
14
|
+
"functions",
|
|
15
|
+
"parser",
|
|
16
|
+
"purge",
|
|
17
|
+
"search",
|
|
18
|
+
"visitor",
|
|
19
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Any, final
|
|
2
|
+
|
|
3
|
+
from pjmespath.visitor import Options
|
|
4
|
+
|
|
5
|
+
@final
|
|
6
|
+
class ParsedResult:
|
|
7
|
+
@property
|
|
8
|
+
def expression(self) -> str: ...
|
|
9
|
+
@property
|
|
10
|
+
def parsed(self) -> dict[str, Any]: ...
|
|
11
|
+
def search(self, value: Any, options: Options | None = None) -> Any: ...
|
|
12
|
+
def _render_dot_file(self) -> str: ...
|
|
13
|
+
def __repr__(self) -> str: ...
|
|
14
|
+
|
|
15
|
+
@final
|
|
16
|
+
class _RustExpression:
|
|
17
|
+
@property
|
|
18
|
+
def expression(self) -> dict[str, Any]: ...
|
|
19
|
+
def visit(self, node: dict[str, Any], value: Any) -> Any: ...
|
|
20
|
+
|
|
21
|
+
def compile(expression: str | bytes | bytearray) -> ParsedResult: ...
|
|
22
|
+
def search(
|
|
23
|
+
expression: str | bytes | bytearray,
|
|
24
|
+
data: Any,
|
|
25
|
+
options: Options | None = None,
|
|
26
|
+
) -> Any: ...
|
|
27
|
+
def purge() -> None: ...
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"ParsedResult",
|
|
31
|
+
"_RustExpression",
|
|
32
|
+
"compile",
|
|
33
|
+
"purge",
|
|
34
|
+
"search",
|
|
35
|
+
]
|