hedge-python 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.
- hedge_python-0.1.0/.github/workflows/ci.yml +71 -0
- hedge_python-0.1.0/.github/workflows/release.yml +111 -0
- hedge_python-0.1.0/.gitignore +210 -0
- hedge_python-0.1.0/CHANGELOG.md +65 -0
- hedge_python-0.1.0/LICENSE +21 -0
- hedge_python-0.1.0/Makefile +58 -0
- hedge_python-0.1.0/PKG-INFO +367 -0
- hedge_python-0.1.0/README.ja.md +258 -0
- hedge_python-0.1.0/README.md +317 -0
- hedge_python-0.1.0/README.zh-CN.md +238 -0
- hedge_python-0.1.0/benchmark/plot.py +246 -0
- hedge_python-0.1.0/eval.png +0 -0
- hedge_python-0.1.0/eval_multi_framework.png +0 -0
- hedge_python-0.1.0/examples/README.md +51 -0
- hedge_python-0.1.0/examples/aiohttp_basic.py +55 -0
- hedge_python-0.1.0/examples/grpc_stream.py +150 -0
- hedge_python-0.1.0/examples/grpc_unary.py +115 -0
- hedge_python-0.1.0/examples/httpx_basic.py +62 -0
- hedge_python-0.1.0/pyproject.toml +98 -0
- hedge_python-0.1.0/src/hedge/__init__.py +17 -0
- hedge_python-0.1.0/src/hedge/_options.py +35 -0
- hedge_python-0.1.0/src/hedge/_stats.py +75 -0
- hedge_python-0.1.0/src/hedge/budget/__init__.py +5 -0
- hedge_python-0.1.0/src/hedge/budget/_token_bucket.py +52 -0
- hedge_python-0.1.0/src/hedge/interceptor/__init__.py +23 -0
- hedge_python-0.1.0/src/hedge/interceptor/_grpc.py +302 -0
- hedge_python-0.1.0/src/hedge/py.typed +0 -0
- hedge_python-0.1.0/src/hedge/sketch/__init__.py +6 -0
- hedge_python-0.1.0/src/hedge/sketch/_ddsketch.py +173 -0
- hedge_python-0.1.0/src/hedge/sketch/_windowed.py +115 -0
- hedge_python-0.1.0/src/hedge/transport/__init__.py +24 -0
- hedge_python-0.1.0/src/hedge/transport/_aiohttp.py +135 -0
- hedge_python-0.1.0/src/hedge/transport/_base.py +159 -0
- hedge_python-0.1.0/src/hedge/transport/_httpx.py +84 -0
- hedge_python-0.1.0/tests/__init__.py +0 -0
- hedge_python-0.1.0/tests/benchmark/__init__.py +0 -0
- hedge_python-0.1.0/tests/benchmark/test_bench_ddsketch.py +69 -0
- hedge_python-0.1.0/tests/benchmark/test_bench_hedge_comparison.py +314 -0
- hedge_python-0.1.0/tests/benchmark/test_bench_multi_framework.py +449 -0
- hedge_python-0.1.0/tests/benchmark/test_bench_token_bucket.py +23 -0
- hedge_python-0.1.0/tests/conftest.py +9 -0
- hedge_python-0.1.0/tests/integration/__init__.py +0 -0
- hedge_python-0.1.0/tests/integration/proto/__init__.py +0 -0
- hedge_python-0.1.0/tests/integration/proto/testservice.proto +37 -0
- hedge_python-0.1.0/tests/integration/proto/testservice_pb2.py +44 -0
- hedge_python-0.1.0/tests/integration/proto/testservice_pb2_grpc.py +142 -0
- hedge_python-0.1.0/tests/integration/test_aiohttp_session.py +145 -0
- hedge_python-0.1.0/tests/integration/test_grpc_interceptor.py +490 -0
- hedge_python-0.1.0/tests/integration/test_httpx_transport.py +192 -0
- hedge_python-0.1.0/tests/unit/__init__.py +0 -0
- hedge_python-0.1.0/tests/unit/test_ddsketch.py +207 -0
- hedge_python-0.1.0/tests/unit/test_grpc_interceptor_branches.py +291 -0
- hedge_python-0.1.0/tests/unit/test_hedge_scheduler.py +181 -0
- hedge_python-0.1.0/tests/unit/test_lazy_imports.py +49 -0
- hedge_python-0.1.0/tests/unit/test_options.py +37 -0
- hedge_python-0.1.0/tests/unit/test_stats.py +96 -0
- hedge_python-0.1.0/tests/unit/test_token_bucket.py +77 -0
- hedge_python-0.1.0/tests/unit/test_transport_import_errors.py +79 -0
- hedge_python-0.1.0/tests/unit/test_windowed_sketch.py +97 -0
- hedge_python-0.1.0/uv.lock +3228 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
lint:
|
|
15
|
+
name: Lint & Type Check
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: astral-sh/setup-uv@v4
|
|
20
|
+
with:
|
|
21
|
+
version: "latest"
|
|
22
|
+
enable-cache: true
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.13"
|
|
26
|
+
- run: uv sync --all-extras
|
|
27
|
+
- run: uv run ruff check src/ tests/
|
|
28
|
+
- run: uv run mypy src/hedge/
|
|
29
|
+
|
|
30
|
+
test:
|
|
31
|
+
name: Test (${{ matrix.os }} / Python ${{ matrix.python-version }})
|
|
32
|
+
runs-on: ${{ matrix.os }}
|
|
33
|
+
strategy:
|
|
34
|
+
fail-fast: false
|
|
35
|
+
matrix:
|
|
36
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
37
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
- uses: astral-sh/setup-uv@v4
|
|
41
|
+
with:
|
|
42
|
+
version: "latest"
|
|
43
|
+
enable-cache: true
|
|
44
|
+
- uses: actions/setup-python@v5
|
|
45
|
+
with:
|
|
46
|
+
python-version: ${{ matrix.python-version }}
|
|
47
|
+
- run: uv sync --all-extras
|
|
48
|
+
- run: uv run pytest tests/unit/ -v --tb=short
|
|
49
|
+
- name: Run integration tests
|
|
50
|
+
timeout-minutes: 5
|
|
51
|
+
run: uv run pytest tests/integration/ -v --tb=short -m integration --timeout=60 --timeout-method=thread
|
|
52
|
+
|
|
53
|
+
coverage:
|
|
54
|
+
name: Coverage
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
needs: test
|
|
57
|
+
steps:
|
|
58
|
+
- uses: actions/checkout@v4
|
|
59
|
+
- uses: astral-sh/setup-uv@v4
|
|
60
|
+
with:
|
|
61
|
+
version: "latest"
|
|
62
|
+
enable-cache: true
|
|
63
|
+
- uses: actions/setup-python@v5
|
|
64
|
+
with:
|
|
65
|
+
python-version: "3.13"
|
|
66
|
+
- run: uv sync --all-extras
|
|
67
|
+
- run: uv run pytest tests/ --cov=src/hedge --cov-report=xml --cov-report=term-missing
|
|
68
|
+
- uses: codecov/codecov-action@v4
|
|
69
|
+
with:
|
|
70
|
+
file: coverage.xml
|
|
71
|
+
fail_ci_if_error: false
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: false
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: Build distributions
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
|
|
21
|
+
- uses: astral-sh/setup-uv@v4
|
|
22
|
+
with:
|
|
23
|
+
version: "latest"
|
|
24
|
+
enable-cache: true
|
|
25
|
+
|
|
26
|
+
- uses: actions/setup-python@v5
|
|
27
|
+
with:
|
|
28
|
+
python-version: "3.13"
|
|
29
|
+
|
|
30
|
+
- name: Verify tag matches pyproject.toml version
|
|
31
|
+
run: |
|
|
32
|
+
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
|
33
|
+
PKG_VERSION="$(uv run python -c 'import tomllib,sys; print(tomllib.loads(open("pyproject.toml","rb").read().decode())["project"]["version"])')"
|
|
34
|
+
echo "Tag version: $TAG_VERSION"
|
|
35
|
+
echo "Package version: $PKG_VERSION"
|
|
36
|
+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
|
|
37
|
+
echo "::error::Git tag ($TAG_VERSION) does not match pyproject.toml version ($PKG_VERSION)"
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
- name: Build sdist and wheel
|
|
42
|
+
run: uv build
|
|
43
|
+
|
|
44
|
+
- name: Check distributions
|
|
45
|
+
run: uv run --with twine twine check dist/*
|
|
46
|
+
|
|
47
|
+
- uses: actions/upload-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: dist
|
|
50
|
+
path: dist/
|
|
51
|
+
if-no-files-found: error
|
|
52
|
+
|
|
53
|
+
publish-testpypi:
|
|
54
|
+
name: Publish to TestPyPI
|
|
55
|
+
needs: build
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
# 仅在 tag 中带有 -rc / -alpha / -beta 等预发标识时发到 TestPyPI
|
|
58
|
+
if: contains(github.ref_name, '-')
|
|
59
|
+
environment:
|
|
60
|
+
name: testpypi
|
|
61
|
+
url: https://test.pypi.org/project/hedge-python/
|
|
62
|
+
permissions:
|
|
63
|
+
id-token: write
|
|
64
|
+
steps:
|
|
65
|
+
- uses: actions/download-artifact@v4
|
|
66
|
+
with:
|
|
67
|
+
name: dist
|
|
68
|
+
path: dist/
|
|
69
|
+
|
|
70
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
71
|
+
with:
|
|
72
|
+
repository-url: https://test.pypi.org/legacy/
|
|
73
|
+
|
|
74
|
+
publish-pypi:
|
|
75
|
+
name: Publish to PyPI
|
|
76
|
+
needs: build
|
|
77
|
+
runs-on: ubuntu-latest
|
|
78
|
+
# 正式版本(不含 - 的 tag,如 v0.1.0、v1.2.3)才发布到正式 PyPI
|
|
79
|
+
if: ${{ !contains(github.ref_name, '-') }}
|
|
80
|
+
environment:
|
|
81
|
+
name: pypi
|
|
82
|
+
url: https://pypi.org/project/hedge-python/
|
|
83
|
+
permissions:
|
|
84
|
+
id-token: write
|
|
85
|
+
steps:
|
|
86
|
+
- uses: actions/download-artifact@v4
|
|
87
|
+
with:
|
|
88
|
+
name: dist
|
|
89
|
+
path: dist/
|
|
90
|
+
|
|
91
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
92
|
+
|
|
93
|
+
github-release:
|
|
94
|
+
name: Create GitHub Release
|
|
95
|
+
needs: [publish-pypi]
|
|
96
|
+
runs-on: ubuntu-latest
|
|
97
|
+
if: ${{ !contains(github.ref_name, '-') }}
|
|
98
|
+
permissions:
|
|
99
|
+
contents: write
|
|
100
|
+
steps:
|
|
101
|
+
- uses: actions/download-artifact@v4
|
|
102
|
+
with:
|
|
103
|
+
name: dist
|
|
104
|
+
path: dist/
|
|
105
|
+
|
|
106
|
+
- name: Create GitHub Release
|
|
107
|
+
uses: softprops/action-gh-release@v2
|
|
108
|
+
with:
|
|
109
|
+
name: ${{ github.ref_name }}
|
|
110
|
+
generate_release_notes: true
|
|
111
|
+
files: dist/*
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# Benchmark per-run outputs (regenerated by `make bench-compare` / `make bench-multi`).
|
|
104
|
+
benchmark/results*.csv
|
|
105
|
+
|
|
106
|
+
# poetry
|
|
107
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
108
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
109
|
+
# commonly ignored for libraries.
|
|
110
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
111
|
+
#poetry.lock
|
|
112
|
+
#poetry.toml
|
|
113
|
+
|
|
114
|
+
# pdm
|
|
115
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
116
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
117
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
118
|
+
#pdm.lock
|
|
119
|
+
#pdm.toml
|
|
120
|
+
.pdm-python
|
|
121
|
+
.pdm-build/
|
|
122
|
+
|
|
123
|
+
# pixi
|
|
124
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
125
|
+
#pixi.lock
|
|
126
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
127
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
128
|
+
.pixi
|
|
129
|
+
|
|
130
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
131
|
+
__pypackages__/
|
|
132
|
+
|
|
133
|
+
# Celery stuff
|
|
134
|
+
celerybeat-schedule
|
|
135
|
+
celerybeat.pid
|
|
136
|
+
|
|
137
|
+
# SageMath parsed files
|
|
138
|
+
*.sage.py
|
|
139
|
+
|
|
140
|
+
# Environments
|
|
141
|
+
.env
|
|
142
|
+
.envrc
|
|
143
|
+
.venv
|
|
144
|
+
env/
|
|
145
|
+
venv/
|
|
146
|
+
ENV/
|
|
147
|
+
env.bak/
|
|
148
|
+
venv.bak/
|
|
149
|
+
|
|
150
|
+
# Spyder project settings
|
|
151
|
+
.spyderproject
|
|
152
|
+
.spyproject
|
|
153
|
+
|
|
154
|
+
# Rope project settings
|
|
155
|
+
.ropeproject
|
|
156
|
+
|
|
157
|
+
# mkdocs documentation
|
|
158
|
+
/site
|
|
159
|
+
|
|
160
|
+
# mypy
|
|
161
|
+
.mypy_cache/
|
|
162
|
+
.dmypy.json
|
|
163
|
+
dmypy.json
|
|
164
|
+
|
|
165
|
+
# Pyre type checker
|
|
166
|
+
.pyre/
|
|
167
|
+
|
|
168
|
+
# pytype static type analyzer
|
|
169
|
+
.pytype/
|
|
170
|
+
|
|
171
|
+
# Cython debug symbols
|
|
172
|
+
cython_debug/
|
|
173
|
+
|
|
174
|
+
# PyCharm
|
|
175
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
176
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
177
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
178
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
179
|
+
.idea/
|
|
180
|
+
|
|
181
|
+
# Abstra
|
|
182
|
+
# Abstra is an AI-powered process automation framework.
|
|
183
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
184
|
+
# Learn more at https://abstra.io/docs
|
|
185
|
+
.abstra/
|
|
186
|
+
|
|
187
|
+
# Visual Studio Code
|
|
188
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
189
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
190
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
191
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
192
|
+
# .vscode/
|
|
193
|
+
|
|
194
|
+
# Ruff stuff:
|
|
195
|
+
.ruff_cache/
|
|
196
|
+
|
|
197
|
+
# PyPI configuration file
|
|
198
|
+
.pypirc
|
|
199
|
+
|
|
200
|
+
# Cursor
|
|
201
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
202
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
203
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
204
|
+
.cursorignore
|
|
205
|
+
.cursorindexingignore
|
|
206
|
+
|
|
207
|
+
# Marimo
|
|
208
|
+
marimo/_static/
|
|
209
|
+
marimo/_lsp/
|
|
210
|
+
__marimo__/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-04-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Core hedge scheduler shared by all transports (`src/hedge/transport/_base.py`)
|
|
13
|
+
with adaptive p90 trigger, token-bucket budget, and warmup phase.
|
|
14
|
+
- DDSketch quantile estimator (`src/hedge/sketch/_ddsketch.py`) and a
|
|
15
|
+
windowed pair (`src/hedge/sketch/_windowed.py`) with background rotation.
|
|
16
|
+
- Token-bucket rate limiter (`src/hedge/budget/_token_bucket.py`) with
|
|
17
|
+
preserved budget percent on RPS changes.
|
|
18
|
+
- Thread-safe `Stats` and immutable `StatsSnapshot` for observability
|
|
19
|
+
(`src/hedge/_stats.py`).
|
|
20
|
+
- `HedgeConfig` dataclass exposing all tunables (`src/hedge/_options.py`).
|
|
21
|
+
- **httpx adapter**: `HedgedHttpxTransport` (`AsyncBaseTransport` subclass).
|
|
22
|
+
- **aiohttp adapter**: `HedgedAiohttpSession` (drop-in `ClientSession` wrapper).
|
|
23
|
+
- **gRPC interceptors**:
|
|
24
|
+
- `HedgedUnaryInterceptor` for unary-unary RPCs.
|
|
25
|
+
- `HedgedServerStreamInterceptor` for unary-stream RPCs (TTFM-based).
|
|
26
|
+
- Lazy import shims (`hedge.transport`, `hedge.interceptor`) so optional
|
|
27
|
+
framework dependencies are only loaded when actually used.
|
|
28
|
+
- **Examples** (`examples/`):
|
|
29
|
+
- `httpx_basic.py`, `aiohttp_basic.py` — public-API demos.
|
|
30
|
+
- `grpc_unary.py`, `grpc_stream.py` — self-contained local-server demos
|
|
31
|
+
that prove hedging actually fires under simulated stragglers.
|
|
32
|
+
- **Benchmarks**:
|
|
33
|
+
- `tests/benchmark/test_bench_hedge_comparison.py` — httpx 4-config
|
|
34
|
+
comparison (No hedging / Static 10ms / Static 50ms / Adaptive).
|
|
35
|
+
- `tests/benchmark/test_bench_multi_framework.py` — httpx vs aiohttp vs
|
|
36
|
+
gRPC, No hedging vs Adaptive.
|
|
37
|
+
- `tests/benchmark/test_bench_ddsketch.py`,
|
|
38
|
+
`tests/benchmark/test_bench_token_bucket.py` — microbenchmarks.
|
|
39
|
+
- `benchmark/plot.py` — renders both CSVs into `eval.png` and
|
|
40
|
+
`eval_multi_framework.png`.
|
|
41
|
+
- **Integration tests** with real local gRPC server
|
|
42
|
+
(`tests/integration/proto/testservice.proto` + generated stubs).
|
|
43
|
+
- Multi-language `README` (English / 简体中文 / 日本語).
|
|
44
|
+
- GitHub Actions CI (`.github/workflows/ci.yml`): lint + typecheck +
|
|
45
|
+
unit/integration tests + coverage gate.
|
|
46
|
+
|
|
47
|
+
### Updated
|
|
48
|
+
|
|
49
|
+
_Initial release — nothing to update yet._
|
|
50
|
+
|
|
51
|
+
### Removed
|
|
52
|
+
|
|
53
|
+
_Initial release — nothing removed._
|
|
54
|
+
|
|
55
|
+
### Other
|
|
56
|
+
|
|
57
|
+
- Test coverage: **97.41%** (122 tests, runs in ~7s without benchmarks).
|
|
58
|
+
- Lint: `ruff` clean across `src/` and `tests/` (generated protobuf stubs
|
|
59
|
+
excluded via `extend-exclude`).
|
|
60
|
+
- `pyproject.toml` declares optional extras: `[httpx]`, `[aiohttp]`,
|
|
61
|
+
`[grpc]`, `[all]`, `[dev]`.
|
|
62
|
+
- Supports Python 3.9 → 3.14.
|
|
63
|
+
|
|
64
|
+
[Unreleased]: https://github.com/sunhailin-Leo/hedge-python/compare/v0.1.0...HEAD
|
|
65
|
+
[0.1.0]: https://github.com/sunhailin-Leo/hedge-python/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LeoSun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
.PHONY: install lint format typecheck test test-unit test-integration bench bench-compare bench-multi bench-plot coverage ci clean
|
|
2
|
+
|
|
3
|
+
# Install dependencies
|
|
4
|
+
install:
|
|
5
|
+
uv sync --all-extras
|
|
6
|
+
|
|
7
|
+
# Linting
|
|
8
|
+
lint:
|
|
9
|
+
uv run ruff check src/ tests/
|
|
10
|
+
|
|
11
|
+
# Auto-fix lint issues
|
|
12
|
+
format:
|
|
13
|
+
uv run ruff format src/ tests/
|
|
14
|
+
uv run ruff check --fix src/ tests/
|
|
15
|
+
|
|
16
|
+
# Type checking
|
|
17
|
+
typecheck:
|
|
18
|
+
uv run mypy src/hedge/
|
|
19
|
+
|
|
20
|
+
# Run all tests
|
|
21
|
+
test:
|
|
22
|
+
uv run pytest tests/ -v --tb=short
|
|
23
|
+
|
|
24
|
+
# Unit tests only
|
|
25
|
+
test-unit:
|
|
26
|
+
uv run pytest tests/unit/ -v --tb=short
|
|
27
|
+
|
|
28
|
+
# Integration tests only
|
|
29
|
+
test-integration:
|
|
30
|
+
uv run pytest tests/integration/ -v --tb=short -m integration
|
|
31
|
+
|
|
32
|
+
# Benchmark tests
|
|
33
|
+
bench:
|
|
34
|
+
uv run pytest tests/benchmark/ -v --benchmark-only --benchmark-sort=mean
|
|
35
|
+
|
|
36
|
+
# Benchmark comparison: no-hedge vs hedge configurations on httpx (outputs CSV + table)
|
|
37
|
+
bench-compare:
|
|
38
|
+
uv run pytest tests/benchmark/test_bench_hedge_comparison.py -v -s --no-header -k test_full_comparison
|
|
39
|
+
|
|
40
|
+
# Multi-framework benchmark: httpx vs aiohttp vs grpc, no-hedge vs adaptive (outputs CSV + table)
|
|
41
|
+
bench-multi:
|
|
42
|
+
uv run pytest tests/benchmark/test_bench_multi_framework.py -v -s --no-header -k test_multi_framework_comparison
|
|
43
|
+
|
|
44
|
+
# Generate evaluation charts (eval.png + eval_multi_framework.png) from benchmark CSVs
|
|
45
|
+
bench-plot:
|
|
46
|
+
uv run python benchmark/plot.py
|
|
47
|
+
|
|
48
|
+
# Coverage report
|
|
49
|
+
coverage:
|
|
50
|
+
uv run pytest tests/ --cov=src/hedge --cov-report=term-missing --cov-report=html
|
|
51
|
+
|
|
52
|
+
# Run full CI checks locally
|
|
53
|
+
ci: lint typecheck test coverage
|
|
54
|
+
|
|
55
|
+
# Clean build artifacts
|
|
56
|
+
clean:
|
|
57
|
+
rm -rf build/ dist/ *.egg-info .pytest_cache .mypy_cache .ruff_cache htmlcov .coverage
|
|
58
|
+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
|