Uv

From archibate/dotfiles-opencode · View interactive version

Uv is an AI agent skill from the GitHub repository archibate/dotfiles-opencode. Use this skill when using UV (Python package manager), needs to set up Python virtual environments, install/manage Python CLI tools, migrate from pip/pipx to UV, Python version management, or troubleshoot UV-related issues.

How to use this skill

Skill file

UV - Python Package Manager Skill

Overview

UV is an extremely fast Python package and project manager written in Rust. This skill provides guidance on using UV for Python development, with particular focus on MCP (Model Context Protocol) server integration and modern tool management workflows.

UV replaces multiple tools: pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more - delivering 10-100x faster performance through intelligent caching and parallel operations.

Version Awareness

Recommended Version: UV 0.9.7+ (Latest as of October 2025)

Before starting, check your UV version:

uv --version

Important Version-Specific Changes:

If your version is older than 0.9.0, upgrade for the best experience:

# Using pip
pip install --upgrade uv

# Or reinstall using official installer
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# Unix/Mac
curl -LsSf https://astral.sh/uv/install.sh | sh

See Recent Changes Reference for detailed version information and migration guidance.

When to Use This Skill

Use this skill when:

Skip this skill when:

Core Concepts

1. UV Commands Overview

UV provides several commands for different use cases:

| Command | Purpose | Example |

|---------|---------|---------|

| uv pip install | Install packages in current environment | uv pip install requests |

| uv tool install | Install CLI tools globally with isolation | uv tool install black |

| uvx | Execute packages in temporary environments | uvx mcp-server-sqlite |

| uv venv | Create virtual environments | uv venv .venv |

| uv python install | Install Python versions | uv python install 3.12 |

2. Tool vs UVX Decision Tree

Need to run a Python package?
|
├─ Use daily/frequently?
|  └─ YES → `uv tool install package`
|     Examples: black, pytest, flake8, mypy
|
├─ MCP server?
|  └─ YES → `uvx package` or `uvx --from path script.py`
|     Examples: mcp-server-sqlite, custom MCP servers
|
├─ Testing/one-off execution?
|  └─ YES → `uvx package`
|     Examples: testing new tools, version comparison
|
└─ Local development script?
   └─ YES → `uvx --from . script.py`
      Examples: project-specific scripts

3. MCP Server Execution Patterns

Published Packages (No working directory needed):

{
  "servers": {
    "sqlite": {
      "command": "uvx",
      "args": ["mcp-server-sqlite", "--db-path", "/path/to/db"]
    }
  }
}

Local Development (Use --from flag):

{
  "servers": {
    "my-server": {
      "command": "uvx",
      "args": [
        "--from", "/absolute/path/to/project",
        "server.py",
        "--config", "config.json"
      ]
    }
  }
}

Key insight: --from flag IS the working directory reference for UVX.

4. Virtual Environment Management

UV works seamlessly with Python's built-in venv:

# Create virtual environment
python -m venv .venv

# Activate (Windows Git Bash)
. .venv/Scripts/activate

# Activate (Windows CMD)
.venv\Scripts\activate.bat

# Activate (Linux/Mac)
source .venv/bin/activate

# Install packages with UV
uv pip install -r requirements.txt

Common Workflows

Development Tools Setup

# Install development tools once
uv tool install black
uv tool install flake8
uv tool install mypy
uv tool install pytest

# Use daily
black .
flake8 src/
mypy src/
pytest tests/

MCP Server Usage

# Test published MCP servers
uvx mcp-server-sqlite --db-path test.db
uvx mcp-server-git --repository /path/to/repo

# Local MCP server development
uvx --from /path/to/project server.py --env config.env

Project Initialization

# Create new project with UV
uv init my-project
cd my-project

# Add dependencies
uv add requests fastapi

# Run project
uv run python main.py

Python Version Management

# List available Python versions
uv python list

# Install default Python version (3.14 in UV 0.9.6+)
uv python install

# Install specific Python version
uv python install 3.12
uv python install 3.13

# Use in project
uv python pin 3.12

Note: As of UV 0.9.6, Python 3.14 is the default version. If you need Python 3.13 or earlier, explicitly specify the version.

Inline Script Dependencies (PEP 723)

UV supports defining dependencies directly in Python script comments:

#!/usr/bin/env -S uv run --script
# /// script
# dependencies = [
#   "requests",
#   "pandas",
# ]
# ///

import requests
import pandas as pd

# Your code here

Run with automatic dependency installation:

# UV installs dependencies automatically
uv run script.py

Benefits:

See Inline Script Metadata Reference for comprehensive examples including MCP servers, web applications, data processing, and CLI tools.

Integration Patterns

VS Code MCP Configuration

For .vscode/mcp.json or user settings:

{
  "servers": {
    "published-server": {
      "type": "stdio",
      "command": "uvx",
      "args": ["mcp-server-sqlite", "--db-path", "${workspaceFolder}/db.sqlite"]
    },
    "local-dev": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "--from", "${workspaceFolder}",
        "src/server.py"
      ]
    }
  }
}

Continue IDE Configuration

For .continue/config.json:

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "uvx",
          "args": ["mcp-server-fetch"]
        }
      }
    ]
  }
}

GitHub Actions CI/CD

- name: Setup UV
  uses: astral-sh/setup-uv@v1

- name: Install dependencies
  run: uv pip install -r requirements.txt

- name: Run tests
  run: uv run pytest

Best Practices

Tool Management

DO:

DON'T:

MCP Server Patterns

DO:

DON'T:

Virtual Environments

DO:

DON'T:

Performance Characteristics

UV's performance advantages:

Typical operation times:

Troubleshooting

Common Issues

"spawn uvx ENOENT" Error:

Package Not Found:

Permission Errors:

Version Conflicts:

See detailed troubleshooting in:

Reference Documentation

This skill includes detailed reference documentation:

  1. Recent Changes ⭐ NEW
  1. Installation & Setup
  1. Tool Management
  1. MCP Integration
  1. Python Environment
  1. Inline Script Metadata
  1. Examples

External Resources

Migration Guides

From pip

# Old way
pip install requests

# New way
uv pip install requests

From pipx

# Old way
pipx install black

# New way
uv tool install black

From poetry

# Old way
poetry add requests
poetry install

# New way
uv add requests
uv sync

Summary

UV provides a unified, fast, and modern approach to Python package management. The key to effective UV usage is:

  1. Understand the tool landscape: uv pip, uv tool, uvx each serve specific purposes
  2. Follow community patterns: Use UVX for MCP servers, uv tool for development tools
  3. Leverage isolation: Each tool gets its own environment preventing conflicts
  4. Use --from for local development: Essential pattern for MCP server development
  5. Keep tools updated: Regular maintenance prevents issues

By following these patterns and utilizing the reference documentation, you'll have a clean, efficient, and maintainable Python development environment.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.