pypi-version-bisect
Binary-search a PyPI package's release history to pin down exactly which
versions a vulnerability affects — the first-affected release, the
last-affected release, and the version that fixed it — using O(log n)
tests instead of installing every version.
You supply an oracle (check_fn(version) -> bool) that decides whether a given
release is vulnerable. This library handles fetching the release timeline from
PyPI (in chronological upload order) and driving an efficient bisection over it.
Install
pip install pypi-version-bisect
Library usage
from pypi_version_bisect import find_affected_range, format_version_range
def check_fn(version: str) -> bool:
# Install the version in a sandbox and probe for the vulnerability.
# Return True if vulnerable, False if clean.
...
result = find_affected_range("pyyaml", check_fn)
print(result["first_affected"]) # e.g. "3.1"
print(result["last_affected"]) # e.g. "5.3.1"
print(result["fixed_in"]) # e.g. "5.4"
print(format_version_range(result)) # ">=3.1,<5.4"
find_affected_range returns a dict with package, all_versions,
first_affected, last_affected, fixed_in, and checked_count. If nothing
could be determined it also includes an error key.
Tuning knobs:
delay(default0.5) — seconds between oracle calls, to be kind to install infrastructure.max_checks(default40) — hard cap on oracle calls. Binary search is logarithmic, so 40 covers thousands of releases.
CLI
List releases in upload order:
pypi-version-bisect list requests
Bisect using an external command as the oracle (exit code 0 = vulnerable):
pypi-version-bisect range examplepkg \
--check-cmd "python probe.py examplepkg=={version}" \
--delay 1.0
Notes
- Only depends on
requests. - Network failures are non-fatal: fetching returns an empty list and the run
reports a clear
errorrather than raising. - Versions are ordered by earliest file upload time, which matches release chronology better than string sorting for pre-releases and hotfixes.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file pypi_version_bisect-0.1.0.tar.gz.
File metadata
- Download URL: pypi_version_bisect-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd564419558f67927e451ad8bac780df3deb5fe2f74ee2ed58b60673a01fe8a4
|
|
| MD5 |
7301e3937d53fd387a6a3b5dd2bd2566
|
|
| BLAKE2b-256 |
edfb4f5b3505e47c9c3976259de453999301c596325530de257e096ecfbb783d
|
File details
Details for the file pypi_version_bisect-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pypi_version_bisect-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffc7b08f9d68bb570c99f97610db40ce2ef8ce79b71e072974dd3170d82cd0e3
|
|
| MD5 |
42ec10522c414c4a069c9b4aa2f4d9c7
|
|
| BLAKE2b-256 |
b9c5ce44778fbb527cc646b5e3d738a516a9523203bdbd2502122b2841156927
|