pip-prune 🧹 — Optimize Your Python requirements.txt Automatically
Demo: pip-prune scanning and optimizing a Python project
pip-prune is a blazing-fast, zero-dependency Python CLI tool that scans your project, detects which packages in requirements.txt are actually used, and rewrites the file to the smallest, version-pinned, lint-clean set.
- Remove unused dependencies
- Pin versions for reproducibility
- Catch dynamic imports with runtime tracing
- Beautiful, colorized terminal output
- CI/CD and GitHub Actions ready
🚀 Use Case: Python Dependency Hygiene & Security
pip-prune is perfect for:
- Python developers who want to keep their
requirements.txtminimal and accurate - Teams enforcing dependency hygiene in CI/CD
- Open source maintainers who want reproducible, clean installs
- Anyone who wants to avoid dependency bloat and security risks
Keywords: python dependency cleaner, requirements.txt optimizer, remove unused python packages, pin python dependencies, python dependency hygiene, python requirements audit, python security, python reproducibility
⚡ Installation (pip)
pip install pip-prune
🛠️ Command Usage & Examples
1. Scan for Used Imports
pip-prune scan --paths src
- Lists all detected imports in your codebase.
2. Rewrite requirements.txt (Dry Run)
pip-prune rewrite --paths src --dry-run
- Shows what would be removed/kept, but does not modify files.
3. Actually Rewrite requirements.txt
pip-prune rewrite --paths src --no-dry-run --yes --inline
- Removes unused packages, pins versions, and updates your file (with backup).
4. Check for Unused Dependencies (CI/CD)
pip-prune check --paths src
- Exits 1 if changes are needed, 0 if clean (great for GitHub Actions).
5. Runtime Tracing for Dynamic Imports
pip-prune scan --paths src python3 main.py
- Runs your command and catches imports loaded at runtime (e.g., plugins, lazy imports).
6. Ignore Rules
pip-prune rewrite --ignore numpy,rich --dry-run
- Always keep specified packages, even if unused.
7. Config File Support
Create .pipprunerc.toml:
[pip-prune]
paths = ["src"]
ignore = ["numpy"]
tracer = false
Then run:
pip-prune rewrite --config .pipprunerc.toml --dry-run
📦 Example Workflow
- Install:
pip install pip-prune
- Scan your project:
pip-prune scan --paths myproject
- Optimize requirements.txt:
pip-prune rewrite --paths myproject --no-dry-run --yes --inline
- Add to CI:
- name: Check requirements run: pip-prune check --paths myproject
🧪 Testing & Development
- Run all tests:
pytest
- Type checking:
mypy pip_prune/ - Linting:
ruff check . black --check .
- Build for PyPI:
python -m build
🌟 Features
- Lightning-fast static AST scan
- Optional runtime tracing for dynamic imports
- Import-to-package resolution with heuristics
- Pretty Rich terminal output (color, icons, tables)
- Ignore rules via CLI, config, or env
- Config file support (
pyproject.toml,.pipprunerc.toml) - CI/CD and GitHub Actions ready
- 100% typed, mypy/ruff/black/isort clean
- Cross-platform: Linux, macOS, Windows (Python 3.9+)
📈 Why pip-prune?
- Save time: No more manual dependency audits
- Reduce risk: Fewer attack surfaces, less bloat
- Reproducibility: Pin exact versions for every install
- DevX: Beautiful, actionable output
📄 License
MIT — see LICENSE
👤 Author & Contact
Author: Sherin Joseph Roy
Email: sherin.joseph2217@gmail.com
GitHub: Sherin-SEF-AI/pip-prune
pip-prune: The fastest way to keep your Python dependencies clean, safe, and minimal.
Metadata
Release files for pip-prune 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pip_prune-0.1.0.tar.gz | 17.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pip_prune-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.2 kB
Release files / pip_prune-0.1.0.tar.gz
| Download URL | pip_prune-0.1.0.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0f4f7344517bb310407b0fa75a23817e0bcd04b14a17e1df60c8c43c812f77d
|
|
BLAKE2b-256 checksum How to use checksums |
2aa40b15f5ddfa444499b5a99e34c129fa2362afd0dfd1e765554d8892985de2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / pip_prune-0.1.0-py3-none-any.whl
| Download URL | pip_prune-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d681bcbc4d915d1211dca925470f8a5d7820d97b1efdd56b68cc3d4d26158986
|
|
BLAKE2b-256 checksum How to use checksums |
d3e7a4ec28afc3c0da58d2fc1e4c314b011bce5f4d95bf5ec96442ac29b828f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|