Skip to main content

philiprehberger-req-check

Tests PyPI version Last updated

Detect unused packages in requirements.txt by scanning imports.

Installation

pip install philiprehberger-req-check

Usage

from philiprehberger_req_check import check

# Find unused packages in a project directory
unused = check("./my-project")
print(unused)  # ["some-unused-package"]

Scan Imports

from philiprehberger_req_check import scan_imports

imports = scan_imports("./my-project")
print(imports)  # {"requests", "flask", "os", "sys", ...}

Read Requirements

from philiprehberger_req_check import read_requirements

packages = read_requirements("requirements.txt")
print(packages)  # ["requests", "flask", "pillow"]

Finding missing dependencies

from philiprehberger_req_check import find_missing

# Imports used in code but NOT declared in requirements.txt
missing = find_missing("requirements.txt", "./src")
print(missing)  # {"yaml"}

Comparing requirements

from philiprehberger_req_check import compare

diff = compare("requirements.old.txt", "requirements.new.txt")
print(diff)
# {"added": ["httpx"], "removed": ["yaml"], "common": ["requests"]}

CLI

python -m philiprehberger_req_check ./my-project

Exits with code 1 if unused packages are found.

API

Function Description
check(path, *, requirements=None) Find unused packages by comparing imports against requirements
scan_imports(path) Scan Python files for top-level import names
read_requirements(path) Read package names from requirements.txt
find_missing(requirements_path, source_dir) Find imports used in source but not declared in requirements
compare(req_a, req_b) Diff two requirements files into added / removed / common

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

⭐ Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Release files for philiprehberger-req-check 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for philiprehberger-req-check 0.2.0
File Size Uploaded
philiprehberger_req_check-0.2.0.tar.gz 186.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for philiprehberger-req-check 0.2.0
File Interpreter ABI Platform
philiprehberger_req_check-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 192.9 kB

Release files / philiprehberger_req_check-0.2.0.tar.gz

Download URL philiprehberger_req_check-0.2.0.tar.gz
Size 186.0 kB
Tags Source
SHA-256 checksum
How to use checksums
27c1fdf3c5ce594da0140a59a6492db238b6d94eac486ff43b14eed17801dc7a
BLAKE2b-256 checksum
How to use checksums
cbd317d64d582dacad14e531de16ac0a3b8137b1dfb9109adb9d30f63700caa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / philiprehberger_req_check-0.2.0-py3-none-any.whl

Download URL philiprehberger_req_check-0.2.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8780ded553292106d91c0cba4ff020704cdc746e9249e3e22e9c8fe2f42e15d5
BLAKE2b-256 checksum
How to use checksums
8127ca2cac9e8fa4bb161d65d761edac61e7a31bfc85df2d2570a437c88b5706
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page