Upgrade only direct dependencies in requirements.txt or pyproject.toml
Project description
upgrade-py-direct-reqs
Upgrade only direct dependencies listed in requirements.txt safely.
A Python CLI tool that lets you review and upgrade only direct dependencies in a project’s requirements.txt or pyproject.toml, while keeping your pinned versions up to date.
Developed by coding agents with guidance from Miteshkumar N Raval.
Features
- Lists outdated direct dependencies.
plancommand provides deterministic, zero-mutation upgrade planning.- Supports both
requirements.txtandpyproject.toml(with[project.dependencies]). upgradecommand applies upgrades with optional package selection.- Blocks major upgrades by default unless explicitly allowed.
- Offers machine-readable JSON payloads for CI and agent automation.
- Produces optional unified diff previews before applying changes.
- Supports private package mirrors by default (Artifactory, Nexus, Azure Artifacts, internal indexes, etc.) because package resolution is delegated to
pipand your existing pip configuration. - Cross-platform: works on Linux, macOS, and Windows.
- Supports Python 3.9–3.13.
GitHub Actions support
This repository includes built-in GitHub Actions CI in .github/workflows/ci.yml.
Quick understanding (for end users)
When code is pushed or a PR is opened, GitHub Actions automatically:
- Checks out the repository
- Creates a Python environment (3.9–3.13)
- Installs dependencies with
pip install .[dev] - Runs
pytest tests/test_cli.py
Trigger events
push(tomain/master)pull_requestworkflow_dispatch(manual run from GitHub UI)
Using private mirrors in Actions
Private mirrors are supported by default. Set your normal pip index configuration in the workflow/job environment (for example PIP_INDEX_URL, PIP_EXTRA_INDEX_URL, or pip config files + secrets).
Where to use this in CI/CD (important)
Use this tool in a dependency-maintenance workflow, not your main deployment pipeline.
- Main CI/deploy pipelines should usually install already-committed dependencies and validate/build/release.
- Maintenance pipelines (for example scheduled weekly jobs) can run
plan --json --diff, optionally runupgrade --yes, and open a PR with the dependency-file changes for review. - Developers can still run the tool locally; the pipeline approach simply centralizes and automates the same process with consistent policy checks.
Installation
# Recommended: install inside your existing project virtual environment
source myenv/bin/activate # or myenv\Scripts\activate on Windows
pip install upgrade-py-direct-reqs
# Optional: install the CLI globally with pipx
pipx install upgrade-py-direct-reqs
Important: Even when installed via
pipx, activate your project's virtual environment before runningupgrade-py-direct-reqsso upgrades are applied to the correct environment.
CLI reference
Syntax:
upgrade-py-direct-reqs [plan|upgrade] FILE [packages ...] [flags]
Commands
plan: compute upgrade candidates only; does not mutate files.upgrade: install upgrades and rewrite direct dependency declarations.
Positional arguments
FILE: dependency file to process (requirements.txtorpyproject.toml).packages ...: optional package names to restrict plan/upgrade scope.
Flags
--python PYTHON_PATH:- Use a specific Python executable.
- Default behavior uses the Python from the active virtual environment (
VIRTUAL_ENV).
--json:- Emit machine-readable JSON output (especially useful for CI/agents).
--yes,-y:- Skip interactive confirmation for
upgrade.
- Skip interactive confirmation for
--allow-major:- Allow major-version bumps. Without this flag, major bumps are blocked and command exits with code
2.
- Allow major-version bumps. Without this flag, major bumps are blocked and command exits with code
--tighten:- Rewrite upgraded constraints as exact pins (
==).
- Rewrite upgraded constraints as exact pins (
--widen:- Widen
</<=style upper-bound constraints to latest available version (rewritten as<=latest).
- Widen
--diff:- Print a unified diff preview of planned changes.
--no-color:- Disable emoji/status symbols.
-v,--version:- Show installed CLI version and exit.
-h,--help:- Show help and usage.
Example usage
# Default plan mode (command omitted)
upgrade-py-direct-reqs requirements.txt
# Flags can precede the file and still default to plan
upgrade-py-direct-reqs --json requirements.txt
# Explicit plan mode
upgrade-py-direct-reqs plan requirements.txt
# Plan + JSON + diff output (CI/agents)
upgrade-py-direct-reqs plan requirements.txt --json --diff
# Plan only for selected packages
upgrade-py-direct-reqs plan requirements.txt requests fastapi
# Upgrade selected packages and skip prompt
upgrade-py-direct-reqs upgrade requirements.txt requests fastapi --yes
# Upgrade from pyproject and allow major versions
upgrade-py-direct-reqs upgrade pyproject.toml --allow-major --yes
# Use explicit Python interpreter
upgrade-py-direct-reqs plan requirements.txt --python .venv/bin/python
# Force exact pins in planned/updated lines
upgrade-py-direct-reqs plan requirements.txt --tighten
# Preview patch-style output
upgrade-py-direct-reqs plan pyproject.toml --diff
# Show version
upgrade-py-direct-reqs --version
Before/after sample (interactive upgrade)
Before (requirements.txt):
requests==2.30.0
flask==2.2.5
Command:
upgrade-py-direct-reqs upgrade requirements.txt
Sample output:
ℹ️ Checking outdated packages via pip. This can take a little while depending on network/index speed...
📦 Planned dependency updates:
flask: 2.2.5 -> 3.0.3 (flask==3.0.3)
requests: 2.30.0 -> 2.32.3 (requests==2.32.3)
Proceed with upgrade? (y/n): y
After (requirements.txt):
requests==2.32.3
flask==3.0.3
AI agent section
When integrating with coding agents (or any automation), use a predictable, policy-driven sequence:
- Discover options using
upgrade-py-direct-reqs --help. - Run
planwith structured output:upgrade-py-direct-reqs plan <file> --json --diff. - Parse and evaluate:
candidatesmajor_blockedchangeddiff(if requested)
- Enforce your policy (for example: block major upgrades unless explicitly approved).
- Execute
upgrade ... --yesonly after policy passes.
In most teams, this sequence is run as a dedicated maintenance pipeline that opens PRs, while regular CI pipelines continue validating pinned dependencies.
Exit code guidance for agents
0: success.1: interactive cancellation.2: major upgrades blocked without--allow-major.3: invalid input file / no direct dependencies found.4: environment issue (missing virtualenv or declared dependencies not installed).5: subprocess failure during upgrade.
Private mirrors for agents
No special tool flags are required for private mirrors. If your environment already uses pip mirror/index configuration, upgrade-py-direct-reqs will use it automatically.
Tests
pip install .[dev]
pytest tests/test_cli.py
The project and CI currently target Python 3.9–3.13.
Current automated coverage in tests/test_cli.py includes:
- invalid TOML filename validation (
pyproject.tomlnaming rule) - normalized package-name matching behavior in plan mode
- upgrade path behavior when dependencies are not installed
- plan
--jsonbehavior in missing-installation guard paths - help output coverage for key option descriptions and examples
License
This project is licensed under the MIT License — see the LICENSE file for details.
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 upgrade_py_direct_reqs-0.6.0.tar.gz.
File metadata
- Download URL: upgrade_py_direct_reqs-0.6.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a670ccc1ce264c7b03409ea588b317fe1fe5522e6665db85f387a9cd345d5234
|
|
| MD5 |
5098a7cbae133cf67f99bed1ab21d149
|
|
| BLAKE2b-256 |
6cfc2eecb34f1d43d975a59dbdb4ef94aa28e0b806a6c93993e506353b8c5323
|
File details
Details for the file upgrade_py_direct_reqs-0.6.0-py3-none-any.whl.
File metadata
- Download URL: upgrade_py_direct_reqs-0.6.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51775509ef8e880680d265dc70ea3e921e0dc8d2d822129ca0af5b94c5a9c7ba
|
|
| MD5 |
4d428cd92f26de911a4c3e1730659729
|
|
| BLAKE2b-256 |
e79217898e9ecc8458f48233941b2cc39a4916e9d0f447b2e1b852ed6c6ffbaa
|