ScanReq - Python tool to scan all unused packages in requirements.txt file for your project.
One popular tool for checking requirements in a Python project is pipdeptree
. However, the problem arises when we don't know which packages listed in the requirements.txt
file are actually being used in the project or not. It's easy to check if your project is small, but as your project grows larger, it becomes a headache to check one by one.
So, this tool comes in handy for easily identifying which exact packages are actually unused in our project.
- Save Money: Remove unused dependencies to lower hosting costs.
- Speed Up: Faster installation and build times mean quicker development.
- Use Resources Wisely: Free up disk and memory space by removing what you don't use.
- Easier Maintenance: Keep your project cleaner and simpler for easier management.
- Focus Better: Work with only what you need, enhancing productivity.
- Update Efficiently: Ensure your dependencies are up-to-date for smoother compatibility.
- Stay Safe: Reduce the chance of security vulnerabilities by trimming unnecessary dependencies.
- Stay Legal: Avoid licensing issues by managing dependencies more effectively.
- Work Together: Simplify collaboration with a consistent set of dependencies.
- Code Better: Keep your documentation and codebase cleaner for improved quality.
pip3 install scanreq
Note: Ensure you're working on python environment & already installed all your project requirements.txt
scanreq -r requirements.txt -p . -o unused-requirements.txt -i black,flake8
[i] Please wait! It may take few minutes to complete...
[i] Scanning unused packages:
1. Module: rcssmin -> Package: rcssmin
2. Module: model_utils -> Package: django-model-utils
3. Module: pinax_theme_bootstrap -> Package: pinax-theme-bootstrap
4. Module: phonenumbers -> Package: phonenumbers
cat unused-requirements.txt
rcssmin
django-model-utils
pinax-theme-bootstrap
phonenumbers
Cool right? ๐
scanreq --help
usage: scanreq [-h] [-r REQUIREMENTS] [-p PATH] [-o OUTPUT] [-i IGNORED_PACKAGES]
Scan for unused Python packages.
optional arguments:
-h, --help show this help message and exit
-r REQUIREMENTS, --requirements REQUIREMENTS
Path to the requirements.txt file to read packages from.
-p PATH, --path PATH Project path to scan for unused packages (default: current directory).
-o OUTPUT, --output OUTPUT
Path to the output file where unused packages will be saved.
-i IGNORED_PACKAGES, --ignored-packages IGNORED_PACKAGES
Comma separated list of package names to be ignored.
Note: Don't forget to cross-check the unused packages after finding them, because sometimes they are used in different cases without being imported in the code. For example:
argon2-cffi
used insettings.PASSWORD_HASHERS = ["django.contrib.auth.hashers.Argon2PasswordHasher", ...]
for Django.
- Support argument parser (command arguments)
- Directory to scan
- Requirement file to scan
- Option to write the output of unused packages
- Option to exclude or ignore some packages
- Option to auto replace the package from requirements.txt file
- Support CLI - make it as a command
- Write some tests
- Publish to PyPi
- Support multiple python versions
- Support multiple devices (Linux, Macbook, and Windows)
- Support scan the
pyproject.toml