Automatic UV-based Python virtual environment management for your shell. No more manual source .venv/bin/activate!
- 🚀 Automatic activation - Activates Python virtual environments when you
cdinto a project - 🐍 UV-powered - Uses UV for lightning-fast environment creation
- 📦 pyproject.toml aware - Reads Python version from
requires-python - 🎯 Zero configuration - Works out of the box
- 🐚 Multi-shell support - Works with Zsh, Bash, and Fish
- ⚡ Performance optimized - Minimal overhead: 8.6ms on shell startup, 1.3ms per directory change
- 🧹 Smart deactivation - Only deactivates environments it activated
- 🛡️ Security focused - Path validation and injection protection
- 📍 Project-aware - Stays active in project subdirectories
- 🔒 Respects manual venvs - Won't interfere with manually activated environments
# Install auto-uv-env
curl -LsSf https://auto-uv-env.ashwch.com/install.sh | shbrew tap ashwch/tap
brew install auto-uv-env# Using the installer from GitHub
curl -LsSf https://raw.githubusercontent.com/ashwch/auto-uv-env/main/docs/install.sh | sh# Clone and install manually
git clone https://github.com/ashwch/auto-uv-env.git
cd auto-uv-env
sudo cp auto-uv-env /usr/local/bin/
sudo mkdir -p /usr/local/share/auto-uv-env
sudo cp share/auto-uv-env/* /usr/local/share/auto-uv-env/# If installed with the installer script
curl -LsSf https://auto-uv-env.ashwch.com/uninstall.sh | sh
# If installed with Homebrew
brew uninstall auto-uv-envAdd to your shell configuration:
# For Homebrew
source $(brew --prefix)/share/auto-uv-env/auto-uv-env.zsh
# For Linux/manual installation
source /usr/local/share/auto-uv-env/auto-uv-env.zsh
# Or if installed via package
source /usr/share/auto-uv-env/auto-uv-env.zsh# For Homebrew
source $(brew --prefix)/share/auto-uv-env/auto-uv-env.bash
# For Linux/manual installation
source /usr/local/share/auto-uv-env/auto-uv-env.bash
# Or if installed via package
source /usr/share/auto-uv-env/auto-uv-env.bash# For Homebrew
source (brew --prefix)/share/auto-uv-env/auto-uv-env.fish
# For Linux/manual installation
source /usr/local/share/auto-uv-env/auto-uv-env.fish
# Or if installed via package
source /usr/share/auto-uv-env/auto-uv-env.fishJust cd into any Python project with a pyproject.toml:
cd my-python-project/
# 🐍 Setting up Python 3.11 with UV...
# ✅ Virtual environment created
# 🚀 UV environment activated (Python 3.11.5)
# Your prompt might look like this (if configured to show Python version):
# (3.11.5) my-python-project $
cd ..
# ⬇️ Deactivated UV environmentThat's it! The virtual environment is automatically:
- Created if it doesn't exist (using Python version from
requires-python) - Activated when you enter the directory
- Deactivated when you leave
AUTO_UV_ENV_QUIET=1- Suppress all status messagesAUTO_UV_ENV_VENV_NAME=.venv- Custom virtual environment directory name (default:.venv)AUTO_UV_ENV_PYTHON_VERSION- Contains the Python version of the currently activated virtual environment. Useful for prompt customization.
[project]
name = "my-project"
requires-python = ">=3.11"auto-uv-env will automatically use Python 3.11 for this project.
- UV - Install with:
curl -LsSf https://astral.sh/uv/install.sh | sh - A shell (Zsh, Bash, or Fish)
- Python projects with
pyproject.toml
- When you
cdinto a directory, auto-uv-env checks forpyproject.toml - If found, it reads the
requires-pythonfield - Uses UV to create a virtual environment with the correct Python version
- Activates the environment automatically
- When you leave the directory, it deactivates the environment
auto-uv-env is designed with performance in mind. Version 1.0.7 includes major optimizations:
- Lazy loading: No overhead for non-Python directories on shell startup
- Command caching: Eliminated repeated lookups for
uvandpython - Native bash parsing: Removed Python fallback for TOML parsing (saves 50-100ms)
- Shell built-ins: Replaced external commands with parameter expansion
- Batch file checks: Combined multiple file system checks
- Shell startup (Python project): 2-3ms (down from 8.6ms)
- Shell startup (non-Python): 0ms (no execution)
- Directory change: <1ms per
cdcommand - First-time setup: 1-5 seconds (UV creates the virtual environment)
For optimal performance:
# Enable quiet mode (saves ~1ms per activation)
export AUTO_UV_ENV_QUIET=1
# Debug mode is now off by default (saves version checks)
# Only enable for troubleshooting:
# export AUTO_UV_ENV_DEBUG=1If you need to disable auto-uv-env in specific directories (e.g., when using direnv), create a .auto-uv-env-ignore file:
# Disable auto-uv-env in this directory
touch .auto-uv-env-ignore| Feature | auto-uv-env | direnv | pyenv-virtualenv |
|---|---|---|---|
| Automatic activation | ✅ | ✅ | ✅ |
| UV integration | ✅ | ❌ | ❌ |
| Zero config | ✅ | ❌ | ❌ |
| Speed | ⚡ Fast | 🐢 Slower | 🐢 Slower |
| Python-specific | ✅ | ❌ | ✅ |
Contributions are welcome! Please follow these steps to contribute:
- UV - Install with:
curl -LsSf https://astral.sh/uv/install.sh | sh - Git
- A shell (Zsh, Bash, or Fish)
-
Clone the repository
git clone https://github.com/ashwch/auto-uv-env.git cd auto-uv-env -
Install development dependencies
uv tool install pre-commit
-
Set up pre-commit hooks
uv tool run pre-commit install
-
Make your changes to the relevant files:
auto-uv-env- Main bash scriptshare/auto-uv-env/- Shell integration filestest/- Test files
-
Run tests
./test/test.sh
-
Check code quality (runs automatically via pre-commit)
uv tool run pre-commit run --all-files
-
Test manually
# Make script executable chmod +x auto-uv-env # Test commands ./auto-uv-env --help ./auto-uv-env --version ./auto-uv-env --check # Test in a Python project cd /path/to/python/project ./auto-uv-env --check
The project uses comprehensive pre-commit hooks that automatically run:
- Code Quality: shellcheck for shell script linting
- Security: detect-secrets for credential scanning
- Formatting: beautysh for shell script formatting
- Testing: Run the test suite before push
- Validation: Syntax checks for all shell integrations
- Project Checks: Version consistency, TODO detection
Run the test suite to ensure everything works:
./test/test.shFor security testing:
./test/test-security.shIf modifying the Homebrew formula:
# Test locally
brew tap-new local/test
cp homebrew/auto-uv-env.rb $(brew --repository)/Library/Taps/local/homebrew-test/Formula/
brew install --build-from-source local/test/auto-uv-env
brew test local/test/auto-uv-env- Use 4-space indentation for shell scripts
- Follow existing patterns and conventions
- Add comments for complex logic
- Ensure all scripts have proper shebangs
- Use shellcheck-compliant code
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following the development workflow
- Ensure all tests pass and pre-commit hooks succeed
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
When reporting issues, please include:
- Operating system and shell type
- UV version (
uv --version) - auto-uv-env version (
auto-uv-env --version) - Steps to reproduce
- Expected vs actual behavior
- Relevant log output
MIT License - see LICENSE file for details.
Created by Ashwini Chaudhary
- UV - The blazing-fast Python package manager
- Inspired by similar tools like direnv and pyenv-virtualenv