A lightning-fast Python CLI that scans your code and optimizes requirements.txt
Project description
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.
Project details
Release history Release notifications | RSS feed
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 pip_prune-0.1.0.tar.gz.
File metadata
- Download URL: pip_prune-0.1.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0f4f7344517bb310407b0fa75a23817e0bcd04b14a17e1df60c8c43c812f77d
|
|
| MD5 |
03a4721c9d65b1f43fc0dc42b97f2795
|
|
| BLAKE2b-256 |
2aa40b15f5ddfa444499b5a99e34c129fa2362afd0dfd1e765554d8892985de2
|
File details
Details for the file pip_prune-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pip_prune-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d681bcbc4d915d1211dca925470f8a5d7820d97b1efdd56b68cc3d4d26158986
|
|
| MD5 |
08395c34ec28a8691cab5b5e5cb688ed
|
|
| BLAKE2b-256 |
d3e7a4ec28afc3c0da58d2fc1e4c314b011bce5f4d95bf5ec96442ac29b828f2
|