Detect unused and undeclared Python dependencies.
reqdiff scans your Python project and reports:
- Unused dependencies — packages listed in your requirements that are never imported
- Undeclared imports — packages imported in your code that are missing from requirements
pip install reqdiff# Scan the current directory
reqdiff .# Scan a specific project
reqdiff /path/to/project
# Point to a specific requirements file
reqdiff . --requirements requirements/prod.txt
# Include dev dependencies
reqdiff . --include-dev
# Suppress specific packages from the unused report
reqdiff . --ignore-package boto3
# Output as JSON (useful for CI tooling)
reqdiff . --jsonScanning: /my/project/**/*.py
Scanned 12 file(s) using 1 requirements source(s)
Unused dependencies (listed in requirements but never imported):
• boto3
Undeclared imports (imported in code but not in requirements):
• httpx
✗ Found 2 issues
Exit codes: 0 = clean, 1 = issues found, 2 = scan error.
| Format | Support |
|---|---|
requirements.txt | ✓ Full (including -r includes) |
pyproject.toml | ✓ PEP 621 [project.dependencies] + Poetry |
setup.cfg | ✓ [options] install_requires |
Add a [tool.reqdiff] section to your pyproject.toml:
[tool.reqdiff]
exclude_dirs = [".venv", "venv", "docs"]
ignore_packages = ["boto3"] # treat as always-usedignore_imports = ["mypy_extensions"] # ignore in undeclared reportinclude_dev = falsefromreqdiffimportrun_checkresult=run_check(".")
print(result.unused_deps) # ["boto3"]print(result.undeclared_imports) # ["httpx"]print(result.has_issues) # True- Dynamic imports (
importlib.import_module("name")) are not detected — only staticimportstatements are analyzed. setup.py(legacy format) is not supported; usepyproject.tomlorsetup.cfginstead.- Packages not installed in the current environment are resolved using a static mapping table. If a package is missing from the table,
reqdifffalls back to treating the import name as the package name.
Contributions welcome! Please open an issue or pull request on GitHub.
MIT