Metadata-Version: 2.4
Name: pypi-version-bisect
Version: 0.1.0
Summary: Binary-search a PyPI package's release history to find the first-affected, last-affected, and fixed version for a vulnerability.
Project-URL: Homepage, https://github.com/krc7169/pypi-version-bisect
Project-URL: Issues, https://github.com/krc7169/pypi-version-bisect/issues
Author-email: krc7169 <krc7169@gmail.com>
License: MIT License
        
        Copyright (c) 2026 krc7169
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: bisect,cve,pypi,security,semver,version,vulnerability
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: requests>=2.20
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# 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

```bash
pip install pypi-version-bisect
```

## Library usage

```python
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` (default `0.5`) — seconds between oracle calls, to be kind to install
  infrastructure.
- `max_checks` (default `40`) — hard cap on oracle calls. Binary search is
  logarithmic, so 40 covers thousands of releases.

## CLI

List releases in upload order:

```bash
pypi-version-bisect list requests
```

Bisect using an external command as the oracle (exit code `0` = vulnerable):

```bash
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 `error` rather 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
