Loading...
Loading...
This skill should be used when the user asks to "set up a Python project with uv", "manage dependencies with uv", "create a uv project", "use uv for Python package management", or needs guidance on uv workflows, pyproject.toml configuration, lockfiles, and development dependency groups.
npx skill4agent add the-perfect-developer/the-perfect-opencode python-uvuv init# Named project in new directory
uv init my-project
cd my-project
# Initialize in current directory
uv initmy-project/
├── .gitignore
├── .python-version
├── README.md
├── main.py
└── pyproject.tomluv runuv syncuv lockmy-project/
├── .venv/
├── .python-version
├── README.md
├── main.py
├── pyproject.toml
└── uv.lockuv run main.pyuv run| File | Purpose | Commit? |
|---|---|---|
| Broad requirements, project metadata | Yes |
| Exact resolved versions, cross-platform | Yes |
| Default Python version for the project | Yes |
| Isolated virtual environment | No |
uv.lock# Add with automatic version constraint
uv add requests
# Add with explicit version constraint
uv add 'requests>=2.31.0'
# Add with extras
uv add 'pandas[excel,plot]'
# Add platform-specific dependency
uv add "jax; sys_platform == 'linux'"# Add to the default dev group (not published to PyPI)
uv add --dev pytest ruff mypy
# Add to named groups for fine-grained control
uv add --group lint ruff
uv add --group test pytest pytest-cov
uv add --group docs mkdocspyproject.toml[dependency-groups]
dev = ["pytest>=8.1.1,<9"]
lint = ["ruff>=0.4.0"]
test = ["pytest", "pytest-cov"][dependency-groups]
lint = ["ruff"]
test = ["pytest"]
dev = [
{include-group = "lint"},
{include-group = "test"},
]# Remove a dependency
uv remove requests
# Upgrade a specific package to latest compatible version
uv lock --upgrade-package requests
# Upgrade all packages
uv lock --upgradeuv run# Run a Python script
uv run main.py
# Run a tool from the environment
uv add flask
uv run -- flask run -p 3000
# Run with a one-off extra dependency (not added to project)
uv run --with rich python -c "import rich; rich.print('[bold]Hello[/bold]')"
# Run only specific dependency groups
uv run --no-default-groups --group test pytest# macOS/Linux
uv sync
source .venv/bin/activate
# Windows
uv sync
.venv\Scripts\activateuv pip installuv addtool.uv.sources# From a local path (editable)
uv add --editable ../my-lib
# From a Git repository
uv add git+https://github.com/encode/httpx
# Pin to a specific Git tag
uv add git+https://github.com/encode/httpx --tag 0.27.0
# From a custom index
uv add torch --index pytorch=https://download.pytorch.org/whl/cpu--no-sourcesuv lock --no-sources
uv build --no-sources# Sync environment to lockfile (installs missing, removes extra)
uv sync
# Sync including all dependency groups
uv sync --all-groups
# Sync only specific groups
uv sync --group test
# Regenerate lockfile without syncing
uv lock
# Check if lockfile is up-to-date (for CI)
uv lock --check# Build source distribution and wheel
uv build
# Check built artifacts
ls dist/
# my-project-0.1.0-py3-none-any.whl
# my-project-0.1.0.tar.gz
# View current package version
uv version
uv version --short # 0.1.0 only
uv version --output-format jsonuv.lockuv lock --checkuv lock --upgrade-package <name>--upgrade--dev--groupuv pip installuv addrequires-pythonpyproject.toml.venv/.gitignoreuv runuvx <tool>uv build --no-sourcestool.uv.sources[project]
name = "my-lib"
version = "0.1.0"
description = "A short description"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"httpx>=0.27.0",
]
[project.optional-dependencies]
network = ["aiohttp>=3.9"]
[dependency-groups]
dev = [
{include-group = "lint"},
{include-group = "test"},
]
lint = ["ruff>=0.4.0", "mypy>=1.10"]
test = ["pytest>=8.0", "pytest-cov>=5.0"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"| Task | Command |
|---|---|
| Create project | |
| Run script | |
| Add dependency | |
| Add dev dependency | |
| Add to named group | |
| Remove dependency | |
| Upgrade package | |
| Sync environment | |
| Rebuild lockfile | |
| Build distributions | |
| Check version | |
| Run tool one-off | |
| Simulate no sources | |
references/dependency-management.mdreferences/project-structure.mdpyproject.tomluv.lock.python-version