phpack 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.
- phpack-0.1.0/.github/workflows/ci.yml +136 -0
- phpack-0.1.0/.gitignore +12 -0
- phpack-0.1.0/Cargo.lock +133 -0
- phpack-0.1.0/Cargo.toml +19 -0
- phpack-0.1.0/LICENSE +22 -0
- phpack-0.1.0/PKG-INFO +72 -0
- phpack-0.1.0/README.md +45 -0
- phpack-0.1.0/SECURITY.md +11 -0
- phpack-0.1.0/benchmarks/bench.py +94 -0
- phpack-0.1.0/pyproject.toml +48 -0
- phpack-0.1.0/python/phpack/__init__.py +30 -0
- phpack-0.1.0/python/phpack/__init__.pyi +71 -0
- phpack-0.1.0/python/phpack/_types.py +51 -0
- phpack-0.1.0/python/phpack/exceptions.py +21 -0
- phpack-0.1.0/python/phpack/hpack.py +7 -0
- phpack-0.1.0/python/phpack/py.typed +0 -0
- phpack-0.1.0/python/phpack/struct.py +19 -0
- phpack-0.1.0/src/huffman.rs +108 -0
- phpack-0.1.0/src/huffman_tables.rs +4365 -0
- phpack-0.1.0/src/lib.rs +552 -0
- phpack-0.1.0/src/simd.rs +143 -0
- phpack-0.1.0/src/table.rs +253 -0
- phpack-0.1.0/tests/test_adversarial.py +115 -0
- phpack-0.1.0/tests/test_concurrency.py +35 -0
- phpack-0.1.0/tests/test_differential.py +116 -0
- phpack-0.1.0/tests/test_ecosystem.py +49 -0
- phpack-0.1.0/tests/test_leaks.py +40 -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 hpack 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/phpack
|
|
87
|
+
stubtest --ignore-disjoint-base phpack
|
|
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
|
phpack-0.1.0/.gitignore
ADDED
phpack-0.1.0/Cargo.lock
ADDED
|
@@ -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 = "phpack"
|
|
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"
|
phpack-0.1.0/Cargo.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "phpack"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
description = "Fast drop-in HPACK header compression for HTTP/2 in Python"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
name = "_phpack"
|
|
11
|
+
crate-type = ["cdylib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
pyo3 = { version = "0.28", features = ["abi3-py39", "extension-module"] }
|
|
15
|
+
|
|
16
|
+
[profile.release]
|
|
17
|
+
lto = "thin"
|
|
18
|
+
codegen-units = 1
|
|
19
|
+
opt-level = 3
|
phpack-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, gatewaytofredom
|
|
4
|
+
Copyright (c) 2015, Cory Benfield and contributors (hpack API & Huffman tables)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
phpack-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: phpack
|
|
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: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Rust
|
|
15
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Summary: Fast drop-in HPACK header compression for HTTP/2 in Python
|
|
19
|
+
Keywords: hpack,http2,header-compression,rust,fast
|
|
20
|
+
License: MIT
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
23
|
+
Project-URL: Homepage, https://github.com/gatewaytofredom/phpack
|
|
24
|
+
Project-URL: Issues, https://github.com/gatewaytofredom/phpack/issues
|
|
25
|
+
Project-URL: Repository, https://github.com/gatewaytofredom/phpack
|
|
26
|
+
|
|
27
|
+
# phpack
|
|
28
|
+
|
|
29
|
+
[](https://github.com/gatewaytofredom/phpack/actions/workflows/ci.yml)
|
|
30
|
+
[](https://pypi.org/project/phpack/)
|
|
31
|
+
[](https://pypi.org/project/phpack/)
|
|
32
|
+
[](https://github.com/gatewaytofredom/phpack/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
Fast drop-in HPACK header compression and decompression for HTTP/2 in Python, delivering 6.1x–7.4x faster header encoding and decoding than pure-Python `hpack` with zero API changes.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install phpack
|
|
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 phpack
|
|
48
|
+
|
|
49
|
+
encoder = phpack.Encoder()
|
|
50
|
+
decoder = phpack.Decoder()
|
|
51
|
+
|
|
52
|
+
wire = encoder.encode([(":method", "GET"), (":path", "/"), ("accept", "application/json")])
|
|
53
|
+
headers = decoder.decode(wire)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Performance
|
|
57
|
+
|
|
58
|
+
| Workload | `hpack` (x86-64) | `phpack` (x86-64 AVX2) | `phpack` (Apple M4 NEON) |
|
|
59
|
+
|---|---:|---:|---:|
|
|
60
|
+
| Small (4 headers, 10k iters) | 89.65 ms | 14.75 ms (6.08x) | 11.53 ms (5.21x vs M4 `hpack`) |
|
|
61
|
+
| Medium (10 headers, 5k iters) | 130.76 ms | 17.65 ms (7.41x) | 14.78 ms (5.24x vs M4 `hpack`) |
|
|
62
|
+
| Large (40 headers, 1k iters) | 99.21 ms | 15.18 ms (6.54x) | 11.85 ms (5.60x vs M4 `hpack`) |
|
|
63
|
+
|
|
64
|
+
## Under the hood
|
|
65
|
+
|
|
66
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
67
|
+
- Compact `cp39-abi3` wheel with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
|
72
|
+
|
phpack-0.1.0/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# phpack
|
|
2
|
+
|
|
3
|
+
[](https://github.com/gatewaytofredom/phpack/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/phpack/)
|
|
5
|
+
[](https://pypi.org/project/phpack/)
|
|
6
|
+
[](https://github.com/gatewaytofredom/phpack/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Fast drop-in HPACK header compression and decompression for HTTP/2 in Python, delivering 6.1x–7.4x faster header encoding and decoding than pure-Python `hpack` with zero API changes.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install phpack
|
|
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 phpack
|
|
22
|
+
|
|
23
|
+
encoder = phpack.Encoder()
|
|
24
|
+
decoder = phpack.Decoder()
|
|
25
|
+
|
|
26
|
+
wire = encoder.encode([(":method", "GET"), (":path", "/"), ("accept", "application/json")])
|
|
27
|
+
headers = decoder.decode(wire)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Performance
|
|
31
|
+
|
|
32
|
+
| Workload | `hpack` (x86-64) | `phpack` (x86-64 AVX2) | `phpack` (Apple M4 NEON) |
|
|
33
|
+
|---|---:|---:|---:|
|
|
34
|
+
| Small (4 headers, 10k iters) | 89.65 ms | 14.75 ms (6.08x) | 11.53 ms (5.21x vs M4 `hpack`) |
|
|
35
|
+
| Medium (10 headers, 5k iters) | 130.76 ms | 17.65 ms (7.41x) | 14.78 ms (5.24x vs M4 `hpack`) |
|
|
36
|
+
| Large (40 headers, 1k iters) | 99.21 ms | 15.18 ms (6.54x) | 11.85 ms (5.60x vs M4 `hpack`) |
|
|
37
|
+
|
|
38
|
+
## Under the hood
|
|
39
|
+
|
|
40
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
41
|
+
- Compact `cp39-abi3` wheel with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT
|
phpack-0.1.0/SECURITY.md
ADDED
|
@@ -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,94 @@
|
|
|
1
|
+
"""Head-to-head microbenchmarks: phpack vs hpack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import statistics
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import phpack
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import hpack
|
|
12
|
+
except ImportError:
|
|
13
|
+
hpack = None # type: ignore[assignment]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
SMALL_HEADERS = [
|
|
17
|
+
(":method", "GET"),
|
|
18
|
+
(":scheme", "https"),
|
|
19
|
+
(":authority", "example.com"),
|
|
20
|
+
(":path", "/"),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
MEDIUM_HEADERS = [
|
|
24
|
+
(":method", "POST"),
|
|
25
|
+
(":scheme", "https"),
|
|
26
|
+
(":authority", "api.example.com"),
|
|
27
|
+
(":path", "/v1/users/profile?include=roles,prefs"),
|
|
28
|
+
("accept", "application/json"),
|
|
29
|
+
("accept-encoding", "gzip, deflate, br"),
|
|
30
|
+
("authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.payload.sig"),
|
|
31
|
+
("content-type", "application/json; charset=utf-8"),
|
|
32
|
+
("user-agent", "httpx/0.28.1"),
|
|
33
|
+
("x-request-id", "f47ac10b-58cc-4372-a567-0e02b2c3d479"),
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
LARGE_HEADERS = [
|
|
37
|
+
*MEDIUM_HEADERS,
|
|
38
|
+
*((f"x-custom-header-{i:02d}", f"value-payload-{i:02d}-" + "abcdefghij" * 4) for i in range(30)),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def bench_one(label: str, headers: list[tuple[str, str]], iters: int) -> None:
|
|
43
|
+
our_enc = phpack.Encoder()
|
|
44
|
+
our_dec = phpack.Decoder()
|
|
45
|
+
# Warm up dynamic table
|
|
46
|
+
our_wire = our_enc.encode(headers)
|
|
47
|
+
our_dec.decode(our_wire)
|
|
48
|
+
|
|
49
|
+
t0 = time.perf_counter()
|
|
50
|
+
for _ in range(iters):
|
|
51
|
+
w = our_enc.encode(headers)
|
|
52
|
+
our_dec.decode(w)
|
|
53
|
+
our_ms = (time.perf_counter() - t0) * 1000.0
|
|
54
|
+
|
|
55
|
+
if hpack is not None:
|
|
56
|
+
ref_enc = hpack.Encoder()
|
|
57
|
+
ref_dec = hpack.Decoder()
|
|
58
|
+
ref_wire = ref_enc.encode(headers)
|
|
59
|
+
ref_dec.decode(ref_wire)
|
|
60
|
+
|
|
61
|
+
t0 = time.perf_counter()
|
|
62
|
+
for _ in range(iters):
|
|
63
|
+
w = ref_enc.encode(headers)
|
|
64
|
+
ref_dec.decode(w)
|
|
65
|
+
ref_ms = (time.perf_counter() - t0) * 1000.0
|
|
66
|
+
speedup = ref_ms / our_ms
|
|
67
|
+
print(
|
|
68
|
+
f"{label:12s} ({iters:5d} iters): hpack={ref_ms:7.2f} ms phpack={our_ms:7.2f} ms speedup={speedup:5.2f}x"
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
print(f"{label:12s} ({iters:5d} iters): phpack={our_ms:7.2f} ms (hpack not installed)")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def main() -> None:
|
|
75
|
+
for label, hdrs, iters in [
|
|
76
|
+
("Small (4)", SMALL_HEADERS, 10_000),
|
|
77
|
+
("Medium (10)", MEDIUM_HEADERS, 5_000),
|
|
78
|
+
("Large (40)", LARGE_HEADERS, 1_000),
|
|
79
|
+
]:
|
|
80
|
+
# Run 3 times and report each; last run is warm
|
|
81
|
+
times = []
|
|
82
|
+
for _ in range(3):
|
|
83
|
+
t0 = time.perf_counter()
|
|
84
|
+
our_enc = phpack.Encoder()
|
|
85
|
+
our_dec = phpack.Decoder()
|
|
86
|
+
for _ in range(iters):
|
|
87
|
+
our_dec.decode(our_enc.encode(hdrs))
|
|
88
|
+
times.append((time.perf_counter() - t0) * 1000.0)
|
|
89
|
+
bench_one(label, hdrs, iters)
|
|
90
|
+
_ = statistics.median(times)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
main()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.7,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "phpack"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Fast drop-in HPACK header compression for HTTP/2 in Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = ["hpack", "http2", "header-compression", "rust", "fast"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Programming Language :: Rust",
|
|
25
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/gatewaytofredom/phpack"
|
|
31
|
+
Repository = "https://github.com/gatewaytofredom/phpack"
|
|
32
|
+
Issues = "https://github.com/gatewaytofredom/phpack/issues"
|
|
33
|
+
|
|
34
|
+
[tool.maturin]
|
|
35
|
+
python-source = "python"
|
|
36
|
+
module-name = "phpack._phpack"
|
|
37
|
+
features = ["pyo3/extension-module"]
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
target-version = "py39"
|
|
41
|
+
line-length = 100
|
|
42
|
+
|
|
43
|
+
[tool.ruff.lint]
|
|
44
|
+
select = ["E", "F", "W", "I", "UP", "B", "SIM"]
|
|
45
|
+
|
|
46
|
+
[tool.mypy]
|
|
47
|
+
python_version = "3.10"
|
|
48
|
+
strict = true
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Fast drop-in HPACK header compression for HTTP/2 in Python."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ._phpack import Decoder, Encoder
|
|
6
|
+
from ._types import (
|
|
7
|
+
HeaderTuple,
|
|
8
|
+
HPACKDecodingError,
|
|
9
|
+
HPACKError,
|
|
10
|
+
InvalidTableIndex,
|
|
11
|
+
InvalidTableIndexError,
|
|
12
|
+
InvalidTableSizeError,
|
|
13
|
+
NeverIndexedHeaderTuple,
|
|
14
|
+
OversizedHeaderListError,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Decoder",
|
|
19
|
+
"Encoder",
|
|
20
|
+
"HPACKDecodingError",
|
|
21
|
+
"HPACKError",
|
|
22
|
+
"HeaderTuple",
|
|
23
|
+
"InvalidTableIndex",
|
|
24
|
+
"InvalidTableIndexError",
|
|
25
|
+
"InvalidTableSizeError",
|
|
26
|
+
"NeverIndexedHeaderTuple",
|
|
27
|
+
"OversizedHeaderListError",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
__version__ = "0.1.0"
|