A tool (and also a pre-commit hook) to automatically check the missing packages in requirements.txt and pyproject.toml.
Project description
check-requirements-txt
A tool (and also a pre-commit hook) to automatically check the missing packages in requirements.txt and pyproject.toml.
Table of Contents
Features
- ✅ Multiple dependency formats: Supports both
requirements.txtandpyproject.toml - ✅ Modern Python projects: Full support for uv package manager and PEP 735 dependency groups
- ✅ Comprehensive TOML parsing:
project.dependencies- Main project dependenciesproject.optional-dependencies- Optional dependencies/extrasdependency-groups- PEP 735 dependency groups with include-group supporttool.uv.dev-dependencies- Legacy uv development dependencies
- ✅ Auto-detection: Automatically finds pyproject.toml and requirements.txt files
- ✅ Python 3.10-3.14: Full compatibility across all modern Python versions
- ✅ Pre-commit integration: Works seamlessly as a pre-commit hook
- ✅ Type-safe: Fully typed with pyright/mypy support
- ✅ Unused dependency detection: Find packages in requirements that aren't used in code
- ✅ Parallel processing: Fast multi-file scanning with configurable workers
Installation
Install using pip:
pip install check-requirements-txt
Or using uv:
uv add --dev check-requirements-txt
Usage
Command Line
Check dependencies in your project:
# Auto-detect pyproject.toml or requirements.txt files
check-requirements-txt src/
# Specify a requirements file
check-requirements-txt src/ -r requirements.txt
# Specify a pyproject.toml file
check-requirements-txt src/ -r pyproject.toml
# Check specific Python files
check-requirements-txt main.py utils.py -r pyproject.toml
# Check for unused dependencies
check-requirements-txt --unused src/
# Use parallel processing for faster scanning
check-requirements-txt --parallel --max-workers 8 src/
提示:目录既可以通过位置参数传入(如
check-requirements-txt src/),也可以使用--dst_dir src/,两者行为一致。
Supported File Formats
pyproject.toml (recommended for modern Python projects):
[project]
dependencies = ["requests>=2.25.0", "packaging"]
[project.optional-dependencies]
dev = ["pytest", "black"]
[dependency-groups]
lint = ["ruff", "mypy"]
test = ["coverage", "pytest-cov"]
[tool.uv]
dev-dependencies = ["pre-commit"]
requirements.txt (traditional format):
requests>=2.25.0
packaging
pytest # dev dependency
Pre-commit Hook
Set up pre-commit hooks for automatic checking:
See pre-commit for instructions
Sample .pre-commit-config.yaml:
Note: Due to the pre-commit isolated environment, this package can't act as a normal git repo pre-commit hook. If your dependency files don't match the default patterns (
*requirement*.txtorpyproject.toml), specify them explicitly.
default_stages: [commit]
repos:
- repo: local
hooks:
- id: check-requirements-txt
name: check-requirements-txt
description: Check missing packages in requirements.txt or pyproject.toml
entry: check-requirements-txt
args: ['--dst_dir', '.', '--ignore', 'pip,whatever,modules,you,want,to,ignore,with,comma,separated']
language: python
types: [python]
For more options, see check-requirements-txt --help.
Output Sample
When missing dependencies are detected:
Bad import detected: "bs4", check your requirements.txt please.
/Users/ferstar/PycharmProjects/xxx_demo/xxx_spider.py:12
Bad import detected: "requests", check your requirements.txt please.
/Users/ferstar/PycharmProjects/xxx_demo/xxx_handler.py:17
"numpy" required by: {'numpy', 'scikit-learn', 'tensorflow', 'pandas'}
# Exit code indicates number of missing dependencies
$ echo $?
2
When using pyproject.toml:
# All dependencies found - no output, exit code 0
$ check-requirements-txt src/ -r pyproject.toml
$ echo $?
0
# Missing dependency detected
$ check-requirements-txt src/ -r pyproject.toml
Bad import detected: "missing_package", check your pyproject.toml please.
/path/to/file.py:5
$ echo $?
1
When checking for unused dependencies:
# Find unused dependencies
$ check-requirements-txt --unused src/
Unused dependencies found in requirements.txt:
- pytest
- black
- unused-package
# Exit code indicates number of issues (missing + unused)
$ echo $?
3
License
check-requirements-txt is distributed under the terms of the MIT license.
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 check_requirements_txt-1.4.2.tar.gz.
File metadata
- Download URL: check_requirements_txt-1.4.2.tar.gz
- Upload date:
- Size: 67.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7c10f07607a4e97f201006607fd4f71849bba2915dd139e82cb2fcd8d93754d
|
|
| MD5 |
fc9df38d6f6922e3ef06f5fe5acdea0d
|
|
| BLAKE2b-256 |
2e0b11907531078998fe4933fa0a1957343c019df94bb5de344788bffb4b98b6
|
Provenance
The following attestation bundles were made for check_requirements_txt-1.4.2.tar.gz:
Publisher:
release.yml on ferstar/check-requirements-txt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
check_requirements_txt-1.4.2.tar.gz -
Subject digest:
d7c10f07607a4e97f201006607fd4f71849bba2915dd139e82cb2fcd8d93754d - Sigstore transparency entry: 940858122
- Sigstore integration time:
-
Permalink:
ferstar/check-requirements-txt@85418b741dee0d0cf802d7cf00743a617f059628 -
Branch / Tag:
refs/tags/v1.4.2 - Owner: https://github.com/ferstar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@85418b741dee0d0cf802d7cf00743a617f059628 -
Trigger Event:
push
-
Statement type:
File details
Details for the file check_requirements_txt-1.4.2-py3-none-any.whl.
File metadata
- Download URL: check_requirements_txt-1.4.2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63d3656ca15d0c9424228ec3fda3f3051b8b0ce7217884f5ee7cda669daae838
|
|
| MD5 |
1a75ea0ce0420eeb14732efcc71b33da
|
|
| BLAKE2b-256 |
e684ca7ba0be338cea931ee58e885b97498cbd6ea5d1e9295e8b43d98db33fb9
|
Provenance
The following attestation bundles were made for check_requirements_txt-1.4.2-py3-none-any.whl:
Publisher:
release.yml on ferstar/check-requirements-txt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
check_requirements_txt-1.4.2-py3-none-any.whl -
Subject digest:
63d3656ca15d0c9424228ec3fda3f3051b8b0ce7217884f5ee7cda669daae838 - Sigstore transparency entry: 940858145
- Sigstore integration time:
-
Permalink:
ferstar/check-requirements-txt@85418b741dee0d0cf802d7cf00743a617f059628 -
Branch / Tag:
refs/tags/v1.4.2 - Owner: https://github.com/ferstar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@85418b741dee0d0cf802d7cf00743a617f059628 -
Trigger Event:
push
-
Statement type: