Available Hooks
The official astral-sh/uv-pre-commit repository provides three hooks:- uv-lock: Update
uv.lockwhenpyproject.tomlchanges - uv-export: Export
uv.locktorequirements.txt - pip-compile: Compile requirements files
Lock File Updates
Automatically update youruv.lock file when pyproject.toml changes:
1
Add hook to .pre-commit-config.yaml
2
Install pre-commit hooks
3
Test the hook
Export Requirements
Keep arequirements.txt file in sync with your uv.lock file:
Custom Export Options
Pass additional arguments to customize the export:Compile Requirements
Compilerequirements.in files to locked requirements.txt files:
Multiple Requirements Files
Compile different requirements files with multiple hook entries:Alternative File Matching
Customize which files trigger the hook:Complete Configuration Example
Here’s a comprehensive pre-commit setup using all three hooks:Version Pinning
Common Use Cases
Python Project with Lock File
Legacy Project with Requirements Files
Project Exporting to Requirements
Running Hooks Manually
Run all hooks on all files:Troubleshooting
Hook Not Running
Ensure pre-commit is installed:Update Hook Versions
Update to the latest hook versions:Skip Hooks Temporarily
Skip hooks for a single commit:SKIP environment variable: