A command line tool designed to manage requirements.txt files in Python projects, particularly useful for monorepo style projects.
It provides functionalities to add, update, remove, find, sort, and view packages in requirements.txt files across specified paths.
- Add: Add a new package to
requirements.txtfiles - Find: Find a package in
requirements.txtfiles across your project - Update: Update an existing package to a new version
- Remove: Remove a package from
requirements.txtfiles - Sort: Sort packages alphabetically in
requirements.txtfiles - Cat: View the contents of
requirements.txtfiles - Versions: Query available versions from PyPI or private indexes
- Smart exclusions: Automatically skips
.venv,venv,virtualenv, and.aws-samdirectories - URL support: Handles VCS URLs (
git+https://...) and PEP 440 URL requirements
This project requires Python 3.11 or higher.
Using uv (recommended for CLI tools):
uv tool install git+https://github.com/CaptainDriftwood/requirements-cli.gitUsing pipx (alternative for CLI tools):
pipx install git+https://github.com/CaptainDriftwood/requirements-cli.gitUsing pip:
pip install git+https://github.com/CaptainDriftwood/requirements-cli.gitgit clone https://github.com/CaptainDriftwood/requirements-cli.git
cd requirements-cli
pip install .requirements catOutputs the contents of all requirements.txt files in the current directory and subdirectories.
requirements cat /path/to/projectView requirements files in a specific path.
requirements cat /path1 /path2View requirements files in multiple paths.
requirements find pandasFind which requirements.txt files contain the pandas package.
requirements find pandas --verboseShow detailed information about where the package is found (displays the actual line from the file).
requirements find django /path/to/monorepoSearch for packages in a specific directory.
requirements add requestsAdd the requests package to all requirements.txt files in the current directory.
requirements add "requests>=2.25.0"Add requests with a specific version constraint.
requirements add flask --previewPreview changes before applying them.
requirements add numpy /path/to/projectAdd a package to requirements files in a specific path.
requirements update requests "2.28.0"Update requests to version 2.28.0 (automatically adds == if no operator specified).
requirements update pandas ">=1.5.0"Update pandas with a version constraint.
requirements update django "4.2.0" --previewPreview update changes before applying.
requirements update flask "2.3.0" /path/to/projectUpdate a package in a specific path.
requirements remove requestsRemove requests from all requirements.txt files.
requirements remove flask --previewPreview which files would be modified before removing.
requirements remove django /path/to/projectRemove a package from requirements files in a specific path.
requirements sortSort all packages alphabetically in requirements.txt files.
requirements sort --previewPreview sorting changes before applying.
requirements sort /path/to/projectSort requirements files in a specific path.
requirements versions requestsShow the 10 most recent versions of a package from PyPI.
requirements versions django --allShow all available versions.
requirements versions requests --limit 20Show a specific number of versions.
requirements versions mypackage --index-url https://nexus.example.com/repository/pypi/simpleQuery versions from a private index (Nexus, Artifactory, etc.).
requirements versions requests -1Print each version on its own line (useful for piping to other commands).
requirements versions requests -1 | head -5
requirements versions django --all -1 | grep "^4\."Pipe output to other commands for filtering.
requirements update numpy "1.21.0" /project1 /project2Apply changes to multiple specific paths.
requirements find django /path1 /path2 /path3Search across multiple directories.
Most commands support --preview to show what changes would be made without applying them:
requirements add fastapi --preview
requirements remove flask --preview
requirements sort --preview
requirements update requests "2.28.0" --previewGlobal options (apply to all commands):
--version: Show the version and exit--help: Show help message--color / --no-color: Enable or disable colored output (auto-detected by default)
All commands:
paths(positional): Specify custom paths to search (default: current directory)
add, remove, update, sort:
--preview: Show what changes would be made without applying them
find:
--verbose: Show the actual package line from the requirements file
versions:
--all: Show all available versions (default: 10 most recent)--limit N: Number of versions to show (default: 10)-1/--one-per-line: Print each version on its own line--index-url URL: Custom PyPI index URL (e.g., private Nexus repository)
The CLI supports colored output using the Rich library for enhanced readability.
Auto-detection (default): Colors are automatically enabled when running in a terminal that supports them.
Manual control:
# Force colors on
requirements --color cat
# Force colors off
requirements --no-color catEnvironment variable:
The CLI respects the NO_COLOR environment variable (no-color.org):
# Disable colors via environment
export NO_COLOR=1
requirements catPriority order:
--color/--no-colorflags (highest priority)NO_COLORenvironment variable- User config file (
~/.requirements/config.toml) - Auto-detection (default)
The CLI supports a configuration file stored in your home directory at ~/.requirements/config.toml.
Initialize config file:
requirements config initSet configuration values:
# Enable colors
requirements config set color.enabled true
# Disable colors
requirements config set color.enabled false
# Set custom PyPI index URL
requirements config set pypi.index_url https://nexus.example.com/simple/
# Set fallback URL (used when primary fails)
requirements config set pypi.fallback_url https://pypi.org/simple/Remove configuration values (reset to default):
requirements config unset pypi.index_url
requirements config unset color.enabledView current settings:
requirements config showShow config file path:
requirements config pathAvailable settings:
| Setting | Type | Description |
|---|---|---|
color.enabled |
bool | Enable/disable colored output |
pypi.index_url |
URL | Primary PyPI index URL for version queries |
pypi.fallback_url |
URL | Fallback URL if primary fails (network errors only) |
Example config file (~/.requirements/config.toml):
[color]
enabled = true
[pypi]
index_url = "https://nexus.example.com/simple/"
fallback_url = "https://pypi.org/simple/"Index URL priority:
--index-urlflag (highest priority)- Config
pypi.index_url - Default PyPI (
https://pypi.org/simple/)
# Find all uses of an old package
requirements find deprecated-package --verbose
# Update across entire monorepo
requirements update deprecated-package "new-package>=1.0.0"
# Clean up and sort all files
requirements sort
# Verify changes
requirements cat | grep new-package# Add a new dependency with preview
requirements add "fastapi[all]>=0.68.0" --preview
# Remove unused packages
requirements remove unused-package --preview
requirements remove unused-package
# Keep requirements files organized
requirements sortThe CLI supports all PEP 440 version specifiers:
# Exact version (== is added automatically if no operator)
requirements update django 4.2.0 # becomes django==4.2.0
# Minimum version
requirements update django ">=4.2.0"
# Compatible release (allows patch updates)
requirements update django "~=4.2.0" # allows 4.2.x but not 4.3.0
# Maximum version
requirements update django "<5.0.0"
# Exclusion
requirements update django "!=4.1.0"
# Range constraints
requirements update django ">=4.0.0,<5.0.0"
# Multiple constraints
requirements update requests ">=2.25.0,!=2.26.0,<3.0.0"
# Pre-release versions
requirements update django ">=4.2.0a1"
# Local version identifiers
requirements update mypackage "==1.0.0+local"Inline comments on package lines are preserved when updating versions:
# Before
django==3.2 # LTS version
flask==2.0
# After running: requirements update django 4.2
django==4.2 # LTS version
flask==2.0Note: Standalone comment lines (lines starting with #) are removed during sorting operations. Only inline comments attached to package lines are preserved.
The following are automatically excluded from searches:
Directories:
.venv,venv,virtualenv- Virtual environment directories.aws-sam- AWS SAM build directories
Symlinks:
- Symlinked files are skipped to prevent infinite loops and unexpected behavior
git clone https://github.com/CaptainDriftwood/requirements-cli.git
cd requirements-cli
uv sync# Run tests
just test
# Run tests with coverage
uv run pytest --cov=src
# Run linting
just lint
# Format code
just format
# Type checking
just type
# Run all checks (format, lint, type, test)
just check
# Run tests across Python versions with nox
just noxjust # Show available recipes
just test # Run all tests
just test-quick # Run tests with minimal output
just test-unit # Run only unit tests (fast, ~0.04s)
just test-integration # Run only integration tests (~0.2s)
just lint # Run ruff linter
just format # Format code with ruff
just type # Run ty type checking
just check # Run all quality checks
just nox # Run tests across Python 3.11, 3.12, 3.13, 3.14
just build # Build the package
just install # Install in development mode
just clean # Clean build artifacts
just upgrade # Upgrade dependencies- Click - CLI framework
- Rich - Terminal formatting and colors
- uv - Python package manager
- Ruff - Linter and formatter
- ty - Type checker
- just - Command runner
- Nox - Test automation
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.