gemini/skills/python/SKILL.md
Use uv for fast Python project management, script execution, dependency handling, and tool installation. AVOID pip - always use uv commands (uv add, uv sync, uv run) instead.
npx skillsauth add lanej/dotfiles pythonInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a Python development specialist using uv, an extremely fast Python package manager and project management tool. This skill provides comprehensive workflows, best practices, and common patterns for Python development with uv.
uv is the modern replacement for pip, virtualenv, poetry, and pyenv combined:
DO NOT use pip commands. Always use uv equivalents:
pip install requests → RIGHT: uv add requestspip install -r requirements.txt → RIGHT: uv syncpip freeze > requirements.txt → RIGHT: uv lock (creates uv.lock)python -m pip install → RIGHT: uv run or uv addThe only exception is legacy projects that explicitly require pip compatibility, and even then prefer migrating to uv.
The most common use case - just run your script:
uv run script.py
uv run script.py arg1 arg2
What this does:
# Run with additional packages
uv run --with requests script.py
uv run --with requests --with pandas analyze.py
# Run with packages from requirements file
uv run --with-requirements requirements.txt script.py
uv run -m module_name
uv run -m pytest tests/
uv run -m black .
# Run a script in isolation
uv run --isolated script.py
# Run with specific Python version
uv run --python 3.11 script.py
# Run with dependencies without a project
uv run --with httpx --with rich my_script.py
# Create application project
uv init my-app
uv init my-app --app
# Create library project
uv init my-lib --lib
# Create script (single file)
uv init my-script --script
# Create in current directory
uv init
# Create without package structure
uv init --bare # Only creates pyproject.toml
Project types:
--app: Application (not meant to be imported)--lib: Library (meant to be published and imported)--script: Single-file script with inline dependencies# Add dependency
uv add requests
uv add "requests>=2.31.0"
uv add requests pandas numpy
# Add dev dependency
uv add --dev pytest
uv add --dev black ruff mypy
# Add optional dependency (extra)
uv add --extra docs sphinx
# Remove dependency
uv remove requests
uv remove --dev pytest
# Update dependencies
uv lock --upgrade
uv lock --upgrade-package requests
# Sync environment with lockfile
uv sync
# Sync without dev dependencies
uv sync --no-dev
# Sync with all extras
uv sync --all-extras
# Sync specific extra
uv sync --extra docs
# Exact sync (remove extraneous packages)
uv sync --exact
# Update lockfile
uv lock
# Update all packages
uv lock --upgrade
# Update specific package
uv lock --upgrade-package requests
# Lock without touching network (use cache only)
uv lock --offline
# Install specific Python version
uv python install 3.11
uv python install 3.12.1
# Install multiple versions
uv python install 3.11 3.12
# List available Python versions
uv python list
# List installed versions
uv python list --only-installed
# Find Python installation
uv python find
uv python find 3.11
# Pin project to specific Python version
uv python pin 3.11
uv python pin 3.12.1
# This creates/updates .python-version file
When you create a project, uv automatically:
.python-version fileuv run commands in that project# Install a tool globally
uv tool install ruff
uv tool install black
uv tool install httpie
# Install specific version
uv tool install "black==24.1.0"
# Run tool without installing
uv tool run ruff check .
uv tool run black --check .
# List installed tools
uv tool list
# Upgrade tools
uv tool upgrade ruff
uv tool upgrade --all
# Uninstall tool
uv tool uninstall ruff
# Show tool directory
uv tool dir
# Linters and formatters
uv tool install ruff # Fast linter and formatter
uv tool install black # Code formatter
uv tool install mypy # Type checker
# Testing
uv tool install pytest # Test framework
uv tool install tox # Test automation
# Utilities
uv tool install httpie # HTTP client
uv tool install rich-cli # Pretty terminal output
uv tool install pipx # Legacy tool installer
# Create venv in current directory
uv venv
# Create with specific Python version
uv venv --python 3.11
# Create in specific location
uv venv path/to/venv
# Create with specific name
uv venv .venv-dev
# Activate (traditional way)
source .venv/bin/activate
# Or just use uv run (recommended)
uv run python script.py
uv run pytest
Best Practice: With uv, you rarely need to manually activate environments. Just use uv run.
WARNING: This interface exists only for legacy compatibility. Prefer native uv commands (uv add, uv sync, uv lock) over uv pip commands.
Only use uv pip when:
Better alternatives:
uv pip install requests → Use uv add requests insteaduv pip install -r requirements.txt → Use uv sync insteaduv pip freeze → Use uv lock instead# Legacy pip-compatible commands (avoid if possible)
uv pip install requests # Better: uv add requests
uv pip install -r requirements.txt # Better: uv sync
uv pip list # Better: uv tree
uv pip show requests # Better: uv tree --package requests
uv pip freeze > requirements.txt # Better: uv lock
uv pip uninstall requests # Better: uv remove requests
# 1. Create project
uv init my-project --app
cd my-project
# 2. Add dependencies
uv add requests httpx rich
# 3. Add dev dependencies
uv add --dev pytest black ruff
# 4. Run your code
uv run python main.py
# 5. Run tests
uv run pytest
# 1. Clone repository
git clone <repo>
cd <repo>
# 2. Sync dependencies (reads pyproject.toml)
uv sync
# 3. Run the application
uv run python main.py
# 4. Run tests
uv run pytest
# Option 1: Inline dependencies in script
cat > script.py << 'EOF'
# /// script
# dependencies = ["requests", "rich"]
# ///
import requests
from rich import print
response = requests.get("https://api.github.com")
print(response.json())
EOF
uv run --script script.py
# Option 2: Command-line dependencies
uv run --with requests --with rich script.py
# Run tests
uv run pytest
uv run pytest tests/
uv run pytest -v --cov
# Format code
uv run black .
uv run ruff format .
# Lint code
uv run ruff check .
uv run ruff check --fix .
# Type check
uv run mypy .
# 1. Check current dependencies
uv tree
# 2. Update all dependencies
uv lock --upgrade
# 3. Update specific package
uv lock --upgrade-package requests
# 4. Sync environment
uv sync
# 5. Run tests to verify
uv run pytest
# Build package
uv build
# Publish to PyPI
uv publish
# Publish to test PyPI
uv publish --index https://test.pypi.org/simple/
Instead of:
# Don't do this
source .venv/bin/activate
python script.py
Do this:
# Do this
uv run script.py
Benefits:
Always create .python-version file:
uv python pin 3.11
This ensures everyone on the team uses the same Python version.
Commit uv.lock to version control:
uv add --dev pytest black ruff mypy
This keeps production dependencies clean.
In pyproject.toml:
[project.scripts]
my-cli = "my_package.cli:main"
[tool.uv]
dev-dependencies = [
"pytest>=7.0.0",
"black>=24.0.0",
]
Then run:
uv run my-cli
my-project/
├── .python-version # Python version (e.g., "3.11")
├── pyproject.toml # Project config and dependencies
├── uv.lock # Lockfile (commit this!)
├── .venv/ # Virtual environment (don't commit)
├── src/
│ └── my_package/
│ ├── __init__.py
│ └── main.py
└── tests/
└── test_main.py
[project]
name = "my-project"
version = "0.1.0"
description = "My awesome project"
requires-python = ">=3.11"
dependencies = [
"requests>=2.31.0",
"rich>=13.0.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"black>=24.0.0",
"ruff>=0.1.0",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.uv]
dev-dependencies = [
"pytest>=7.0.0",
"black>=24.0.0",
]
# Run with optional dependencies
uv run --extra docs sphinx-build
uv run --all-extras pytest
# Add to specific group
uv add --group test pytest
# Run with specific group
uv run --group test pytest
# Sync specific group
uv sync --group test
# Use .env file
uv run --env-file .env script.py
# Override env file
uv run --no-env-file script.py
# Work without network
uv run --offline script.py
uv sync --offline
uv lock --offline
# Use custom PyPI index
uv add requests --index https://my-pypi.org/simple/
# Use multiple indexes
uv add package --index https://index1.org/simple/ --index https://index2.org/simple/
Solution: Update shell PATH
uv tool update-shell
# Then restart shell or source config
Solution: Install Python with uv
uv python install 3.11
uv python pin 3.11
Solution: Force sync
uv sync --reinstall
uv sync --exact
Solution: Clear cache
uv cache clean
uv run --no-cache script.py
Solution: Regenerate lock
uv lock --upgrade
uv sync
# Skip lockfile updates in CI
uv sync --frozen
uv run --frozen pytest
uv automatically caches packages. To see cache:
uv cache dir
uv automatically parallelizes operations. No configuration needed.
# Old way
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python script.py
# New way
uv run script.py # That's it!
# Old: poetry install && poetry run python script.py
# New:
uv sync && uv run python script.py
# Old: pipenv install && pipenv run python script.py
# New:
uv sync && uv run python script.py
uv run pytest
uv run pytest --cov --cov-report=html
uv run black .
uv run ruff check --fix .
uv run mypy src/
uv add --dev jupyter
uv run jupyter notebook
# Run script
uv run script.py
# Run with dependencies
uv run --with requests script.py
# Project setup
uv init my-project
uv add package-name
uv add --dev pytest
# Environment management
uv sync
uv lock --upgrade
# Python management
uv python install 3.11
uv python pin 3.11
# Tools
uv tool install ruff
uv tool run black .
# Legacy compatibility (AVOID - use uv add/sync instead)
uv pip install package # DON'T USE - use: uv add package
uv pip install -r requirements.txt # DON'T USE - use: uv sync
# Testing and quality
uv run pytest
uv run black .
uv run ruff check .
| Task | Old Way | uv Way |
|------|---------|--------|
| Create venv | python -m venv .venv | uv venv (or automatic) |
| Activate | source .venv/bin/activate | Not needed with uv run |
| Install deps | pip install -r requirements.txt | uv sync |
| Run script | python script.py | uv run script.py |
| Add package | pip install requests | uv add requests |
| Global tool | pip install black | uv tool install black |
uv run --with pandas --with matplotlib analyze.py
uv run pytest && uv run black --check . && uv run ruff check .
uv lock --upgrade && uv sync && uv run pytest
uv run --python 3.11 script.py
uv tool run ruff check . # Installs if needed, then runs
Primary directive: Use uv run for executing Python scripts and commands.
Key advantages:
Most common commands:
uv run script.py - Run anythinguv add package - Add dependencyuv sync - Sync environmentuv python pin 3.11 - Set Python versiondata-ai
Delegate research and context-gathering tasks to a sub-agent to protect the primary context window. Use when the user asks to "research X", "look into X", "find out about X", "gather context on X", or any investigative framing where answering requires 2+ searches or multiple sources. Also use proactively before starting substantive work when prior context is unknown. Never run research inline — always delegate.
documentation
--- name: qmd-math description: Math notation conventions for Quarto/EPQ documents rendered via lualatex. Use when: writing or adding a formula, equation, or mathematical expression to a .qmd file; asked about display math, inline math, or LaTeX notation in a QMD/Quarto context; defining a where-clause or variable definitions for an equation; converting prose variable descriptions into structured math notation; fixing math that renders badly in a PDF; using \lvert, \begin{aligned}, \tfrac, \text
development
Trim a prose document (README, design doc, blog post, notes) for readability by cutting redundancy, filler, and dead weight in the author's own words. Invoke with /trim [file path], or /trim alone to be prompted for a file. Not for source code, data files, or summarization.
business
Query and analyze Josh Lane's org headcount from the staffing DuckDB at ~/workspace/areas/staffing/staffing.duckdb. Use when asked about headcount counts, org structure, direct reports, team breakdown, hiring/attrition trends, international employees, salary/pay grade distribution, offboarding lag, or any question about people in Josh's org. Triggers on questions about how many people, who reports to whom, headcount by team/country/level, who joined or left, org size, staffing, headcount trend.