Automatically use 'uv run' when executing Python scripts
Project description
auto-uv
Automatically use uv run when executing Python scripts. Just type python script.py instead of uv run script.py!
What is This?
auto-uv is a Python package that intercepts script execution and automatically uses uv to run them. Install it once, then forget about it - your scripts just work with proper dependency management.
Installation
pip install auto-uv
That's it! Now when you run python script.py, it automatically uses uv run behind the scenes.
Quick Start
# Install
pip install auto-uv
# Run any script - auto-uv handles the rest
python your_script.py
# Disable temporarily if needed
AUTO_UV_DISABLE=1 python your_script.py
How It Works
When you install auto-uv, it uses the hatch-autorun plugin to automatically run code when Python starts. This code checks if:
- You're running a script file (not interactive mode)
uvis available on your system- You're not already running under
uv run
If all conditions are met, it re-executes your script with uv run, giving you automatic dependency management.
Requirements
- Python 3.9+
uvinstalled and in your PATH
Install uv:
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux
# or
pip install uv
Configuration
Environment Variables
AUTO_UV_DISABLE: Set to1,true, oryesto disable auto-uvUV_RUN_ACTIVE: Automatically set by auto-uv (don't set manually)
Disabling auto-uv
# Temporarily disable
AUTO_UV_DISABLE=1 python script.py
# Permanently disable (add to your shell profile)
export AUTO_UV_DISABLE=1
Development
Setup
# Clone the repository
git clone https://github.com/xRiskLab/auto-uv.git
cd auto-uv
# Install with all dev dependencies
uv pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Or use the Makefile
make dev
Testing
# Run tests
make test
# Run tests with act (local GitHub Actions)
make act-test
# Format and lint
make format lint
# Full CI pipeline locally
make ci
Available Make Targets
make help # Show all available commands
make dev # Setup development environment
make test # Run tests
make lint # Run linters
make format # Format code
make build # Build package with uv
make publish-test # Publish to Test PyPI
make publish # Publish to PyPI
make clean # Clean build artifacts
make act-test # Test with act (local GitHub Actions)
make pre-commit # Run pre-commit hooks
make commit # Format, lint, and test before commit
Publishing Manually
# 1. Get token from https://pypi.org/manage/account/token/
# 2. Add to .env file (already in .gitignore)
echo "UV_PUBLISH_TOKEN=pypi-AgE..." >> .env
# 3. Build and publish (Makefile auto-loads .env)
make publish-test
# 4. If successful, publish to PyPI
make publish
Testing with Act
Test GitHub Actions workflows locally before pushing:
# Install act
brew install act # macOS
# or see: https://github.com/nektos/act
# Optional: Create .env file for secrets (if needed)
echo "GITHUB_TOKEN=your_token_here" > .env
# Test workflows
make act-test # Quick test
make act-lint # Test linting
make act-all # Test everything
Version Management
Bump version using GitHub Actions:
gh workflow run version-bump.yml -f version_type=patch # 0.1.0 -> 0.1.1
gh workflow run version-bump.yml -f version_type=minor # 0.1.0 -> 0.2.0
gh workflow run version-bump.yml -f version_type=major # 0.1.0 -> 1.0.0
Or use the Makefile:
make version-patch # Bump patch version
make version-minor # Bump minor version
make version-major # Bump major version
CI/CD
The project includes three GitHub Actions workflows:
- test.yml - Run tests on multiple Python versions (3.9-3.12) and OS (Ubuntu, macOS, Windows)
- workflow.yml - Build and publish to PyPI on release (required name for PyPI)
- version-bump.yml - Automated version management
Troubleshooting
Installing packages in a uv project
Use uv add to manage dependencies:
# Add runtime dependency
uv add requests
# Add development dependency
uv add --dev pytest
# Add multiple packages
uv add --dev mypy black ruff
Can't install packages
If auto-uv is interfering:
# Option 1: Disable auto-uv temporarily
AUTO_UV_DISABLE=1 pip install package-name
# Option 2: Uninstall auto-uv if not needed
pip uninstall auto-uv
Auto-uv not working
# Check if uv is installed
uv --version
# Check if auto-uv is installed
python -c "import auto_uv; print('Installed')"
# Test manually
python -c "import os; print('UV_RUN_ACTIVE:', os.environ.get('UV_RUN_ACTIVE'))"
Contributing
Contributions welcome! Here's the quick workflow:
# 1. Fork and clone
git clone https://github.com/YOUR_USERNAME/auto-uv.git
cd auto-uv
# 2. Setup
make dev
# 3. Create branch
git checkout -b feature/your-feature
# 4. Make changes and test
make commit
# 5. Test with act
make act-test
# 6. Push and create PR
git push origin feature/your-feature
gh pr create
See CONTRIBUTING.md for detailed guidelines.
Why auto-uv?
Without auto-uv:
uv run script.py # Have to remember uv run every time
With auto-uv:
python script.py # Just works!
Benefits:
- ✅ Seamless workflow
- ✅ Automatic dependency management via uv
- ✅ Zero configuration
- ✅ Easy to disable when needed
- ✅ Safe fallback if uv not available
Inspiration
Inspired by pyauto-dotenv which automatically loads .env files.
License
MIT License - see LICENSE file for details.
Links
- Repository: https://github.com/xRiskLab/auto-uv
- Issues: https://github.com/xRiskLab/auto-uv/issues
- uv: https://github.com/astral-sh/uv
- hatch-autorun: https://github.com/pypa/hatch
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 auto_uv-0.1.2.tar.gz.
File metadata
- Download URL: auto_uv-0.1.2.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28a2b28df3d09a6bdd4c9cd2571d4ed0f065f6175fbe3aafd9829936b13b91c0
|
|
| MD5 |
8ffc412f05297cda4f25d706c449d238
|
|
| BLAKE2b-256 |
1a36cc2d1cc3849c7e39220fd3379d62efe0a62c26560a1c051c0fafd203bf74
|
Provenance
The following attestation bundles were made for auto_uv-0.1.2.tar.gz:
Publisher:
workflow.yml on xRiskLab/auto-uv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auto_uv-0.1.2.tar.gz -
Subject digest:
28a2b28df3d09a6bdd4c9cd2571d4ed0f065f6175fbe3aafd9829936b13b91c0 - Sigstore transparency entry: 715464230
- Sigstore integration time:
-
Permalink:
xRiskLab/auto-uv@7547bf8759774c756d293bb6a5b0308e921a6ef5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/xRiskLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@7547bf8759774c756d293bb6a5b0308e921a6ef5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file auto_uv-0.1.2-py3-none-any.whl.
File metadata
- Download URL: auto_uv-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.6 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 |
936ec058bc8912d05b9a8dd6807beecc13bacd8caad08e657d2b3d7a643b0601
|
|
| MD5 |
ca3feebd2a506d62a87c9a118c811516
|
|
| BLAKE2b-256 |
f9555737a87ced94cdfe39cad89ea489adb6d899e06265a05ef3071f416304bd
|
Provenance
The following attestation bundles were made for auto_uv-0.1.2-py3-none-any.whl:
Publisher:
workflow.yml on xRiskLab/auto-uv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auto_uv-0.1.2-py3-none-any.whl -
Subject digest:
936ec058bc8912d05b9a8dd6807beecc13bacd8caad08e657d2b3d7a643b0601 - Sigstore transparency entry: 715464231
- Sigstore integration time:
-
Permalink:
xRiskLab/auto-uv@7547bf8759774c756d293bb6a5b0308e921a6ef5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/xRiskLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@7547bf8759774c756d293bb6a5b0308e921a6ef5 -
Trigger Event:
release
-
Statement type: