Hierarchical UV Virtual Environment Manager
Project description
huv - Hierarchical UV Virtual Environment Manager
A powerful wrapper around uv that creates hierarchical virtual environments where child environments can inherit packages from parent environments with proper precedence handling.
โจ Features
- ๐๏ธ Hierarchical Virtual Environments: Create child environments that inherit from parent environments
- ๐ฆ Smart Package Management: Automatically skip installing packages that are already available from parent environments
- ๐ Dependency Analysis: Full dependency tree analysis to avoid duplicate installations
- โก Storage Efficient: Minimize disk usage by sharing common packages across environments
- ๐ฏ Version Conflict Detection: Detect and handle version conflicts between parent and child environments
- ๐ ๏ธ Complete uv Compatibility: Full support for all uv venv and pip install flags and options
- ๐ง Seamless Integration: Drop-in replacement for uv with added hierarchical capabilities
๐ Requirements
- Python 3.8+
- uv installed and available in PATH
Install uv if you haven't already:
Linux/macOS:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows (PowerShell):
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Windows (via winget):
winget install astral-sh.uv
๐ Installation
Option 1: Install via pip (Recommended)
pip install huv
Option 2: Run standalone executable
# Download the standalone executable
curl -LsSf https://github.com/your-org/huv/releases/latest/download/huv -o huv
chmod +x huv
# Move to a directory in your PATH (optional)
mv huv /usr/local/bin/
Option 3: Install from source
git clone https://github.com/your-org/huv.git
cd huv
pip install .
๐ Quick Start
Create a Root Environment
# Create a root environment with common packages
huv venv .vroot
Activating on Linux/macOS:
cd .vroot && source bin/activate
uv pip install numpy pandas requests
deactivate && cd ..
Activating on Windows:
cd .vroot && Scripts\activate.bat
uv pip install numpy pandas requests
deactivate && cd ..
Create Child Environments
# Create a child environment that inherits from .vroot
huv venv .vchild --parent .vroot
Activating on Linux/macOS:
cd .vchild && source bin/activate
# numpy, pandas, requests are already available from parent!
python -c "import numpy, pandas, requests; print('All packages available!')"
Activating on Windows:
cd .vchild && Scripts\activate.bat
# numpy, pandas, requests are already available from parent!
python -c "import numpy, pandas, requests; print('All packages available!')"
Smart Package Installation
# Install matplotlib - huv will skip numpy (available from parent)
huv pip install matplotlib
# Output:
# ๐ Analyzing dependencies...
# ๐ Found 11 total packages (including dependencies)
# ๐ฆ Dependency 'numpy' (v2.3.3 available from parent)
# ๐ฆ Dependency 'packaging' (v25.0 available from parent)
# ๐ฅ Installing 8 package(s)
# โญ๏ธ Skipped 3 package(s) available from parent
๐ง Commands
Environment Creation
# Create a standalone environment
huv venv myenv
# Create a hierarchical environment
huv venv child-env --parent parent-env
# Pass through uv options
huv venv myenv --python 3.11 --seed
Virtual Environment Options
huv supports all uv venv parameters while adding hierarchical functionality:
Core Environment Options
# Initialize with seed packages (pip, setuptools, wheel)
huv venv myenv --seed
# Clear existing environment if it exists
huv venv myenv --clear
# Custom prompt name
huv venv myenv --prompt "MyProject"
# Include system site packages
huv venv myenv --system-site-packages
Python Version Control
# Specify Python version
huv venv myenv --python 3.11
huv venv myenv -p python3.12
# Use managed Python installations
huv venv myenv --managed-python 3.11
Package Index Configuration
# Custom package index
huv venv myenv --index https://custom-index.com/simple/
# Default index configuration
huv venv myenv --default-index
# Find links for packages
huv venv myenv --find-links https://download.pytorch.org/whl/
huv venv myenv -f ./local-packages/
Performance and Caching Options
# Control file linking behavior
huv venv myenv --link-mode copy # Copy files instead of hard links
huv venv myenv --link-mode hardlink # Use hard links (default)
huv venv myenv --link-mode symlink # Use symbolic links
# Cache management
huv venv myenv --cache-dir /custom/cache/path
huv venv myenv --refresh # Refresh package metadata
# Combined hierarchical and performance options
huv venv child --parent .base --seed --python 3.11 --link-mode copy
Package Management
# Smart install (skips packages from parent)
huv pip install package1 package2
# Install from requirements files
huv pip install -r requirements.txt
# Editable installs
huv pip install -e ./my-package
# Install with constraints
huv pip install -c constraints.txt package1
# Install with extras
huv pip install package[extra1,extra2]
huv pip install --extra security requests
# Upgrade packages
huv pip install -U package1
# Custom indexes
huv pip install --index-url https://custom-index.com package1
huv pip install --extra-index-url https://extra-index.com package1
# Advanced options
huv pip install --no-deps package1 # Skip dependencies
huv pip install --user package1 # User install
huv pip install --target ./lib package1 # Target directory
# Uninstall with parent visibility
huv pip uninstall package1
๐ฏ Use Cases
Development Environments
Linux/macOS:
# Base environment with common tools
huv venv .base
source .base/bin/activate && uv pip install pytest black ruff mypy
# Project-specific environments
huv venv project1 --parent .base # Inherits pytest, black, etc.
huv venv project2 --parent .base # Inherits pytest, black, etc.
Windows:
# Base environment with common tools
huv venv .base
.base\Scripts\activate.bat && uv pip install pytest black ruff mypy
# Project-specific environments
huv venv project1 --parent .base # Inherits pytest, black, etc.
huv venv project2 --parent .base # Inherits pytest, black, etc.
Machine Learning Workflows
Linux/macOS:
# Base ML environment
huv venv .ml-base
source .ml-base/bin/activate && uv pip install numpy pandas scikit-learn
# Experiment environments
huv venv experiment1 --parent .ml-base # + tensorflow
huv venv experiment2 --parent .ml-base # + pytorch
Windows:
# Base ML environment
huv venv .ml-base
.ml-base\Scripts\activate.bat && uv pip install numpy pandas scikit-learn
# Experiment environments
huv venv experiment1 --parent .ml-base # + tensorflow
huv venv experiment2 --parent .ml-base # + pytorch
Microservices
Linux/macOS:
# Shared utilities environment
huv venv .shared
source .shared/bin/activate && uv pip install requests pydantic fastapi
# Service-specific environments
huv venv auth-service --parent .shared # + additional auth packages
huv venv user-service --parent .shared # + additional user packages
Windows:
# Shared utilities environment
huv venv .shared
.shared\Scripts\activate.bat && uv pip install requests pydantic fastapi
# Service-specific environments
huv venv auth-service --parent .shared # + additional auth packages
huv venv user-service --parent .shared # + additional user packages
๐๏ธ How It Works
-
Environment Creation:
huv venvcreates a standard uv virtual environment with full support for all uv venv parameters, then modifies the activation scripts to include parent environment paths inPYTHONPATH -
Package Resolution:
huv pip installanalyzes the complete dependency tree and checks which packages are already available from parent environments -
Smart Installation: Only packages not available from parents are installed, using
--no-depswhen necessary to avoid conflicts -
Precedence: Child environment packages always take precedence over parent packages
๐ฅ๏ธ Cross-Platform Support
huv works seamlessly across Linux, macOS, and Windows with automatic OS detection and platform-specific handling:
Platform Differences
- Linux/macOS: Uses
bin/activatescripts andlib/python*/site-packagesdirectories - Windows: Uses
Scripts\activate.batscripts andLib\site-packagesdirectories
Activation Commands
Linux/macOS:
source myenv/bin/activate
Windows Command Prompt:
myenv\Scripts\activate.bat
Windows PowerShell:
myenv\Scripts\Activate.ps1
Environment Structure
Linux/macOS:
myenv/
โโโ bin/
โ โโโ activate
โ โโโ activate.fish
โ โโโ activate.csh
โ โโโ activate.nu
โ โโโ python
โโโ lib/
โ โโโ python3.x/
โ โโโ site-packages/
โโโ pyvenv.cfg
Windows:
myenv\
โโโ Scripts\
โ โโโ activate.bat
โ โโโ Activate.ps1
โ โโโ python.exe
โโโ Lib\
โ โโโ site-packages\
โโโ pyvenv.cfg
All huv features work identically across platforms - only the activation commands differ.
๐ Complete Flag Support
huv provides comprehensive support for both uv venv and uv pip install commands while maintaining hierarchical functionality.
Requirements and Constraints
# Requirements files (with comments and empty lines supported)
huv pip install -r requirements.txt -r dev-requirements.txt
# Constraint files
huv pip install -c constraints.txt package1
# Editable installs
huv pip install -e ./my-package -e git+https://github.com/user/repo.git
Package Sources and Indexes
# Custom package indexes
huv pip install -i https://custom-index.com/simple/ package1
huv pip install --extra-index-url https://extra-index.com/simple/ package1
# Find links (local or remote archives)
huv pip install -f https://example.com/packages/ package1
huv pip install -f ./local-packages/ package1
# Ignore PyPI entirely
huv pip install --no-index -f ./local-packages/ package1
Package Extras and Dependencies
# Install with extras
huv pip install --extra security --extra testing requests
huv pip install --all-extras package1
# Control dependency installation
huv pip install --no-deps package1 # Skip dependencies entirely
Upgrade and Reinstall Options
# Upgrade packages
huv pip install -U package1 # Upgrade specific package
huv pip install -P package1 -P package2 # Upgrade specific packages
# Force reinstallation
huv pip install --force-reinstall package1
Installation Targets
# User installation
huv pip install --user package1
# Custom target directory
huv pip install --target ./mylib package1
# Custom prefix
huv pip install --prefix /opt/myapp package1
Build Control
# Control wheel/source usage
huv pip install --no-binary package1 # Force source build
huv pip install --only-binary package1 # Only use wheels
huv pip install --no-build package1 # Don't build sources
# Security requirements
huv pip install --require-hashes -r requirements.txt
๐ง Environment Management
Python Version Consistency
huv automatically ensures Python version consistency in hierarchical environments:
# Create parent with Python 3.11
huv venv .parent --python 3.11
# Child automatically inherits Python 3.11
huv venv child --parent .parent # Uses Python 3.11 automatically
# Error if trying to use different version
huv venv child --parent .parent --python 3.10 # โ Error: Version mismatch
Environment Information
Check environment hierarchy:
cat child/pyvenv.cfg | grep huv_parent
# Output: huv_parent = /path/to/.parent
Verify package inheritance:
Linux/macOS:
source child/bin/activate
python -c "import sys; print(sys.path)" # Shows parent paths
Windows:
child\Scripts\activate.bat
python -c "import sys; print(sys.path)" # Shows parent paths
Cleanup and Management
# Remove environments (children first)
rm -rf child/
rm -rf .parent/
# Check what packages come from where
huv pip list # Shows local packages only
pip list # Shows all packages (including inherited)
๐ ๏ธ Advanced Usage
Advanced Installation Options
Version Constraints
# huv respects version constraints
huv pip install "numpy>=1.20" # Skips if parent has compatible version
huv pip install "numpy>=2.0" # Installs if parent has numpy 1.x
Multiple Requirements Sources
# Combine requirements files, constraints, and packages
huv pip install -r requirements.txt -c constraints.txt package1 package2
# Install with multiple requirement files
huv pip install -r base-requirements.txt -r dev-requirements.txt
# Mix editable and regular packages
huv pip install -e ./my-lib package1 package2
Build and Installation Control
# Control build process
huv pip install --no-build package1 # Don't build from source
huv pip install --no-binary :all: package1 # Force source builds
huv pip install --only-binary :all: package1 # Only use wheels
# Reinstall packages
huv pip install --force-reinstall package1
# Security options
huv pip install --require-hashes -r locked-requirements.txt
Multiple Inheritance Levels
huv venv .base
huv venv .ml --parent .base
huv venv .deep-learning --parent .ml # Inherits from both .ml and .base
Advanced Environment Configuration
# Create optimized hierarchical environments
huv venv .base --seed --python 3.11 --link-mode hardlink
huv venv project1 --parent .base --prompt "Project1" --clear
# Development environment with custom index
huv venv dev --parent .base --index https://test.pypi.org/simple/ --seed
# Performance-optimized environment
huv venv fast-env --parent .base --link-mode copy --cache-dir ./local-cache
Development Workflow
# Create development environment structure
huv venv .deps # Common dependencies
huv venv .tools --parent .deps # + development tools
huv venv myproject --parent .tools # + project-specific packages
๐ Troubleshooting
Common Issues
Environment Creation Fails
# Error: Path already exists
rm -rf existing-path && huv venv existing-path
# Error: Parent environment not found
huv venv child --parent /path/to/missing # Check parent path
Package Installation Issues
# Force installation if dependency analysis fails
huv pip install --no-deps package-name
# Clear cache if having dependency resolution issues
uv cache clean
# Check what packages are inherited
Linux/macOS:
source child/bin/activate
python -c "import package; print(package.__file__)" # Shows source location
Windows:
child\Scripts\activate.bat
python -c "import package; print(package.__file__)" # Shows source location
Python Version Issues
Linux/macOS:
# Check parent Python version
parent-env/bin/python --version
# Create child with explicit version matching parent
huv venv child --parent parent-env --python 3.11
Windows:
# Check parent Python version
parent-env\Scripts\python.exe --version
# Create child with explicit version matching parent
huv venv child --parent parent-env --python 3.11
Performance Tips
- Use
--link-mode hardlinkfor fastest environment creation - Share a base environment across multiple projects to save disk space
- Use
--no-depsfor packages when you know dependencies are satisfied by parents - Keep environment hierarchies shallow (2-3 levels max) for best performance
Debugging
# Enable verbose output for uv operations
export UV_VERBOSE=1
huv pip install package-name
# Check inheritance chain
huv venv child --parent .parent --verbose # If supported
# Manual inspection of environment
cat child/pyvenv.cfg
Check activation script modifications:
Linux/macOS:
cat child/bin/activate # Check PYTHONPATH modifications
Windows:
type child\Scripts\activate.bat # Check PYTHONPATH modifications
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Project Structure
huv is designed as a single standalone executable for maximum portability:
huv # Main executable (Python script)
โโโ README.md # Documentation
โโโ LICENSE # MIT License
โโโ pyproject.toml # Build configuration
The huv file contains the complete application and can be run directly without installation. This design makes it easy to:
- Distribute as a single file
- Run without complex dependencies
- Integrate into existing workflows
- Deploy in containerized environments
Development Setup
# Clone and setup development environment
git clone https://github.com/your-org/huv.git
cd huv
# Run tests
./run_tests.sh
# Or run specific tests
python tests/test_huv.py
# Test manually
./huv venv test-env
./huv venv test-child --parent test-env
Running Tests
The project includes comprehensive tests:
# Run all tests (unit + integration)
./run_tests.sh
# Run only unit tests
python tests/test_huv.py
# Run with Python's unittest
python -m unittest tests.test_huv
# Run specific test
python tests/test_huv.py TestHuv.test_create_hierarchical_venv
Code Quality
The project maintains high code quality standards:
- Comprehensive test coverage (15+ test cases)
- GitHub Actions CI/CD for multi-platform testing
- Support for Python 3.8+ across Linux, macOS, and Windows
- Automated testing on every commit
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built on top of the excellent uv package manager
- Inspired by the need for more efficient virtual environment management
- Thanks to the Python packaging community for the tools and standards
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 huv-0.3.0.tar.gz.
File metadata
- Download URL: huv-0.3.0.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddd36ecf044a70cc5075e061cebfc486311f4e1267f77e10de9e2522e999dd64
|
|
| MD5 |
80f5a5798cae294da6790e3ce8a1169d
|
|
| BLAKE2b-256 |
aa4a569a37450d3a236d0554562cba6e12bb02389a7a507234837c42904d380b
|
Provenance
The following attestation bundles were made for huv-0.3.0.tar.gz:
Publisher:
release.yml on abuss/huv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
huv-0.3.0.tar.gz -
Subject digest:
ddd36ecf044a70cc5075e061cebfc486311f4e1267f77e10de9e2522e999dd64 - Sigstore transparency entry: 621062064
- Sigstore integration time:
-
Permalink:
abuss/huv@10774ecd27de6055486445b2c49a2a918550657f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/abuss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10774ecd27de6055486445b2c49a2a918550657f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file huv-0.3.0-py3-none-any.whl.
File metadata
- Download URL: huv-0.3.0-py3-none-any.whl
- Upload date:
- Size: 20.3 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 |
e4a4dd02a6539ced80f363c437bae77bf5c2599296096cb349426120362d0b31
|
|
| MD5 |
c7a21b88e09bb3414e8e9088dfe3547b
|
|
| BLAKE2b-256 |
8e342af2983b321f42fa953f8d4dda733a22f2a06f108c060e638a98d004c4b8
|
Provenance
The following attestation bundles were made for huv-0.3.0-py3-none-any.whl:
Publisher:
release.yml on abuss/huv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
huv-0.3.0-py3-none-any.whl -
Subject digest:
e4a4dd02a6539ced80f363c437bae77bf5c2599296096cb349426120362d0b31 - Sigstore transparency entry: 621062067
- Sigstore integration time:
-
Permalink:
abuss/huv@10774ecd27de6055486445b2c49a2a918550657f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/abuss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10774ecd27de6055486445b2c49a2a918550657f -
Trigger Event:
workflow_dispatch
-
Statement type: