Unlike pip-tools, uv
package manager currently doesn’t support automatically updating pyproject.toml
based on the lock file. This script helps automate that process by reading the versions from uv.lock
and updating your pyproject.toml
accordingly.
Features of the Script
- Automatically updates both main dependencies and dependency groups
- Removes duplicate version constraints
- Preserves dependency extras (e.g.,
fastapi[standard]
) - Creates a backup of
pyproject.toml
before making changes
Prerequisites
- Python 3.11+
tomli-w
package (pip install tomli-w
)- An updated
uv.lock
file (uv lock --update
oruv lock -U
)
Usage Instructions
- Update your lock file:
uv lock -U
- Run the script:
python upgrade_pyproject.py
Script
You can find the full script below:
Comments powered by Disqus.