Loading...
Loading...
Manages Python project dependencies with uv. Learn how to add, remove, and updates dependencies, organize them into groups (dev, test, lint, docs), pin versions, handle conflicts, and manages lock files for reproducible installations across environments. Use when adding or updating packages, organizing development dependencies, resolving version conflicts, or managing lock files in CI/CD pipelines.
npx skill4agent add dawiddutoit/custom-claude uv-dependency-management# Add a package with version constraint
uv add "requests>=2.31.0"
# View your dependency tree
uv tree
# Update all dependencies to latest compatible versions
uv lock --upgradepyproject.tomluv.lock[project]
dependencies = [
"fastapi>=0.104.0",
"sqlalchemy>=2.0.0",
][project.optional-dependencies]
database = ["psycopg2-binary>=2.9.0"]
aws = ["boto3>=1.34.0"][dependency-groups]
dev = ["pytest>=8.0.0", "black>=23.0.0"]
test = ["pytest-cov>=4.1.0"]
lint = ["ruff>=0.1.0", "mypy>=1.7.0"]uv add requests httpx
uv add "fastapi>=0.104.0"
uv add "django>=4.2,<5.0"uv add --dev pytest # Add to 'dev' group
uv add --group test pytest-cov # Add to 'test' group
uv add --group lint ruff mypy # Add to 'lint' groupuv add "pandas[excel,plot]"
uv add --dev "pytest[cov]"uv add "requests" # Latest
uv add "requests>=2.31.0" # Minimum version
uv add "requests>=2.31.0,<3.0.0" # Range (major bump)
uv add "requests~=2.31.0" # Compatible release (~= 2.31.x)
uv add "requests==2.31.0" # Exact version (production)>=>=X,<Y~=uv remove requests
uv remove pytest black # Remove multipleuv add "requests@2.32.0"uv sync --upgrade # Update and sync
uv lock --upgrade # Just update lock filepyproject.toml[dependency-groups]
dev = [
"pytest>=8.0.0",
"pytest-cov>=4.1.0",
"black>=23.0.0",
]
lint = [
"ruff>=0.1.0",
"mypy>=1.7.0",
"pylint>=3.0.0",
]
docs = [
"mkdocs>=1.5.0",
"mkdocs-material>=9.0.0",
]uv sync --group dev --group lint # Install groups
uv sync --all-groups # Install everything
uv sync --no-dev # Only main deps (production)uv.lockpyproject.toml# After changing pyproject.toml
uv sync # Installs from lock or creates new lock
# To explicitly update lock file
uv lock --upgrade # Update all to latest compatible
# In CI/CD (use frozen to prevent surprises)
uv sync --frozen # Fails if lock is out of syncuv add "package-a"
uv add "package-b" # Might fail with version conflict
# Try adding with different constraints
uv add "package-a>=1.0,<2.0"
uv add "package-b>=2.0,<3.0"[dependency-groups]
ml-cpu = ["torch-cpu>=2.0"]
ml-gpu = ["torch-gpu>=2.0"]# Install one group at a time
uv sync --group ml-cpu# See what's needed
uv add --dry-run "package-a" "package-b"
# One might need updating
uv add "package-a>=2.0"
uv add "package-b>=3.0"# Initialize and add web dependencies
uv init my-api
cd my-api
uv add fastapi uvicorn sqlalchemy pydantic
# Add development tools
uv add --group dev pytest pytest-asyncio
uv add --group lint ruff mypy black
# Verify setup
uv tree[project]
name = "my-api"
version = "0.1.0"
dependencies = [
"fastapi>=0.104.0",
"uvicorn>=0.24.0",
"sqlalchemy>=2.0.0",
"pydantic>=2.5.0",
]
[dependency-groups]
dev = ["pytest>=8.0.0", "pytest-asyncio>=0.21.0"]
lint = ["ruff>=0.1.0", "mypy>=1.7.0", "black>=23.0.0"]# Create library with core deps
uv init my-library
uv add "click>=8.1.0"
# Add optional features as extras
uv add --group excel "openpyxl>=3.0.0"
uv add --group database "sqlalchemy>=2.0.0"
uv add --group async "aiohttp>=3.8.0"
# Setup development tools
uv add --dev pytest# Trying to add packages with conflicting requirements
uv add package-a # Works fine
uv add package-b # Fails - needs different version of shared lib
# View what's going on
uv add --dry-run package-b
# Try different constraints
uv add "package-a>=1.0,<1.5"
uv add "package-b>=2.0,<2.5"
# Check if it works
uv tree# Create project
uv init data-pipeline
cd data-pipeline
# Data science core
uv add pandas numpy scikit-learn
# Analysis tools
uv add jupyter matplotlib seaborn plotly
# Development
uv add --group dev pytest pytest-cov
# Final tree
uv tree# Initial setup with compatible ranges
uv add "requests>=2.31.0,<3.0.0"
uv add "fastapi>=0.104.0,<1.0.0"
# After testing on latest patch
uv add "requests@2.31.3"
uv add "fastapi@0.104.1"
# Lock file is frozen for production
git add uv.lock
git commit -m "Pin exact versions for production"
# CI/CD uses frozen lock
uv sync --frozen# Main project
uv init main-app
cd main-app
# Add local packages (editable)
uv add --editable ../shared-lib
uv add --editable ../utils-lib
# Now imports work from both packagescurl -LsSf https://astral.sh/uv/install.sh | shuv init