| name | uv-package-manager |
| version | 1.0.0 |
| description | UV for fast Python package management, virtual environments, and project workflows |
| author | workspace-hub |
| category | devtools |
| tags | ["uv","python","package-manager","virtual-environment","dependency-management"] |
| platforms | ["python","linux","macos","windows"] |
UV Package Manager Skill
Master UV for blazing-fast Python package management, virtual environment creation, and modern Python project workflows.
When to Use This Skill
Use UV package manager when you need:
- Fast dependency installation - 10-100x faster than pip
- Virtual environment management - Create and manage venvs effortlessly
- Project initialization - Start new Python projects quickly
- Dependency resolution - Reliable, reproducible dependency trees
- Lock file management - Ensure consistent environments across machines
- Python version management - Install and switch Python versions
Avoid when:
- Legacy systems requiring pip compatibility (rare)
- Conda-based scientific computing environments
- Docker images with pre-installed pip workflows
Installation
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
brew install uv
pip install uv
Core Capabilities
1. Project Initialization
Create a new Python project:
uv init my-project
cd my-project
uv init
uv init --python 3.11
Project structure created:
my-project/
├── .python-version # Python version lock
├── pyproject.toml # Project configuration
├── README.md # Project readme
└── src/
└── my_project/
└── __init__.py
2. Virtual Environment Management
Create and activate virtual environments:
uv venv
uv venv --python 3.11
uv venv .venv-test
source .venv/bin/activate
.venv\Scripts\activate
source .venv/Scripts/activate
List available Python versions:
uv python list
uv python install 3.12
uv python pin 3.11
3. Dependency Management
Add dependencies:
uv add pandas
uv add numpy scipy matplotlib
uv add "pandas>=2.0,<3.0"
uv add --dev pytest pytest-cov ruff
uv add --optional ml tensorflow torch
uv add git+https://github.com/user/repo.git
uv add --editable ../my-local-package
Remove dependencies:
uv remove pandas
uv remove --dev pytest
Sync dependencies:
uv sync
uv sync --dev
uv sync --extra ml
uv sync --all-extras
4. Lock File Management
Understanding uv.lock:
uv lock
uv lock --python 3.11
uv lock --upgrade
uv lock --upgrade-package pandas
Lock file structure:
version = 1
requires-python = ">=3.9"
[[package]]
name = "pandas"
version = "2.2.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "numpy" },
{ name = "python-dateutil" },
{ name = "pytz" },
]
5. Running Scripts and Commands
Run Python scripts:
uv run python script.py
uv run python -m pytest
uv run --python 3.11 python script.py
Run tools:
uv run pytest tests/
uv run ruff check src/
uv run black src/
uv run mypy src/
6. pip Compatibility Mode
Use UV as a pip replacement:
uv pip install pandas numpy
uv pip install -r requirements.txt
uv pip install -e .
uv pip compile requirements.in -o requirements.txt
uv pip sync requirements.txt
uv pip freeze > requirements.txt
uv pip show pandas
Complete Examples
Example 1: New Project Setup
#!/bin/bash
PROJECT_NAME=${1:-"my-project"}
uv init "$PROJECT_NAME"
cd "$PROJECT_NAME"
uv python pin 3.11
uv add pandas numpy pyyaml click
uv add --dev pytest pytest-cov ruff mypy black isort
uv add --optional viz plotly matplotlib
mkdir -p src/"${PROJECT_NAME//-/_}" tests data docs
touch src/"${PROJECT_NAME//-/_}"/__init__.py
cat > tests/test_example.py << 'EOF'
def test_import():
"""Test that package can be imported."""
import sys
assert 'my_project' in sys.modules or True
EOF
cat > .gitignore << 'EOF'
.venv/
__pycache__/
*.pyc
.pytest_cache/
.mypy_cache/
.ruff_cache/
dist/
*.egg-info/
.coverage
htmlcov/
EOF
uv run pytest tests/ -v
echo "Project $PROJECT_NAME initialized successfully!"
echo "Activate with: source .venv/bin/activate"
Example 2: Migrate from pip to UV
#!/bin/bash
cp requirements.txt requirements.txt.bak 2>/dev/null || true
if [ ! -f pyproject.toml ]; then
uv init --no-readme
fi
if [ -f requirements.txt ]; then
echo "Migrating dependencies from requirements.txt..."
while IFS= read -r line; do
[[ "$line" =~ ^#.*$ ]] && continue
[[ -z "$line" ]] && continue
uv add "$line" 2>/dev/null || echo "Skipped: $line"
done < requirements.txt
fi
if [ -f requirements-dev.txt ]; then
echo "Migrating dev dependencies..."
while IFS= read -r line; do
[[ "$line" =~ ^#.*$ ]] && continue
[[ -z "$line" ]] && continue
uv add --dev 2>/dev/null ||
< requirements-dev.txt
uv --dev
Example 3: CI/CD Pipeline with UV
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Install UV
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --dev
- name: Run linting
Example 4: Multi-Environment Management
#!/bin/bash
create_env() {
local py_version=$1
local env_name=".venv-py${py_version//./}"
echo "Creating environment for Python $py_version..."
uv venv "$env_name" --python "$py_version"
source "$env_name/bin/activate"
uv sync
deactivate
echo "Created: $env_name"
}
create_env 3.10
create_env 3.11
create_env 3.12
echo "Running tests across environments..."
for env in .venv-py*; do
echo "Testing with $env..."
source "$env/bin/activate"
uv run pytest tests/ -q
deactivate
done
Example 5: Workspace-Hub Project Setup
#!/bin/bash
PROJECT_NAME=${1:-"new-project"}
TEMPLATE_REPO="workspace-hub/pyproject-starter"
uv init "$PROJECT_NAME"
cd "$PROJECT_NAME"
uv python pin 3.11
uv add \
pyyaml \
pandas \
numpy \
plotly \
click
uv add --dev \
pytest \
pytest-cov \
ruff \
mypy \
black \
isort \
deepdiff
mkdir -p \
src/"${PROJECT_NAME//-/_}" \
tests \
docs \
data/raw \
data/processed \
data/results \
reports \
config \
scripts
touch src/"${PROJECT_NAME//-/_}"/__init__.py
cat > tests/conftest.py << 'EOF'
"""Pytest configuration and fixtures."""
import pytest
from pathlib import Path
@pytest.fixture
def project_root():
"""Return project root directory."""
return Path(__file__).parent.parent
@pytest.fixture
def data_dir(project_root):
"""Return data directory."""
return project_root / "data"
@pytest.fixture
def test_data_dir(project_root):
"""Return test data directory."""
return project_root / /
EOF
> CLAUDE.md <<
```bash
uv --dev
uv run pytest tests/ -v
uv run ruff check src/
uv run black src/ tests/
uv run isort src/ tests/
uv run mypy src/
Project Structure
src/ - Source code
tests/ - Test files
docs/ - Documentation
data/ - Data files (raw, processed, results)
reports/ - Generated HTML reports
config/ - Configuration files
EOF
echo "Project $PROJECT_NAME created with workspace-hub patterns!"
## Best Practices
### 1. Version Pinning
```bash
# Always pin Python version for reproducibility
uv python pin 3.11
# Use version ranges in pyproject.toml
# [project]
# requires-python = ">=3.10,<3.13"
2. Lock File Hygiene
git add uv.lock
uv lock --upgrade
git diff uv.lock
3. Dependency Groups
[project]
dependencies = [
"pandas>=2.0",
"numpy>=1.24",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0",
"ruff>=0.1.0",
]
viz = [
"plotly>=5.0",
"matplotlib>=3.7",
]
ml = [
"scikit-learn>=1.3",
"tensorflow>=2.15",
]
[tool.uv]
dev-dependencies = [
"pytest>=7.0",
"ruff>=0.1.0",
]
4. Scripts Configuration
[project.scripts]
my-cli = "my_project.cli:main"
[tool.uv.scripts]
test = "pytest tests/ -v"
lint = "ruff check src/"
format = "black src/ tests/"
typecheck = "mypy src/"
all = ["lint", "typecheck", "test"]
5. Performance Tips
uv sync
export UV_CACHE_DIR="$HOME/.cache/uv"
uv sync --offline
uv sync --no-dev --no-extras
Common Commands Reference
| Command | Description |
|---|
uv init | Initialize new project |
uv venv | Create virtual environment |
uv add <pkg> | Add dependency |
uv add --dev <pkg> | Add dev dependency |
uv remove <pkg> | Remove dependency |
uv sync | Install all dependencies |
uv lock | Update lock file |
uv run <cmd> | Run command in venv |
uv python list | List Python versions |
uv python install | Install Python version |
uv pip install | pip compatibility mode |
uv build | Build package |
uv publish | Publish to PyPI |
Resources
Use UV for all Python projects in workspace-hub!