uv-usage
uv Usage
Quick start
Use uv as a fast, unified tool for Python projects:
- Initialize a project:
uv init - Add deps:
uv add <package> - Sync env:
uv sync - Run commands:
uv run <cmd>
uv add updates uv.lock automatically; use uv lock when you need to re-lock after manual pyproject.toml edits.
Inline dependencies (PEP 723 scripts)
Use inline metadata so a script runs standalone with uv run <script-file>.
Steps
- Add a
# /// scriptblock at the top of the file. - Set
requires-pythonanddependencies. - Run the script with
uv run <script-file>. - Add or remove inline deps with
uv add --scriptanduv remove --script.
Template
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests>=2.31",
# "rich>=13.0",
# ]
# ///
import requests
from rich import print
print(requests.get("https://api.github.com/repos/astral-sh/uv").status_code)
Commands
uv run script.py
uv add --script script.py beautifulsoup4
uv remove --script script.py rich
Pip-compatible commands
Use these for drop-in workflows or legacy projects:
uv pip install <package>
uv pip install -r requirements.txt
uv pip compile requirements.in -o requirements.txt
uv pip sync requirements.txt
Python versions and environments
uv python install 3.12
uv python pin 3.12
uv venv --python 3.12
uv run --python 3.12 -- python -V
Examples
New project
uv init demo
cd demo
uv add ruff
uv run ruff check .
Standalone script with inline deps
uv run script.py
Notes
- uv offers pip-compatible commands, but behavior can differ in edge cases.
- Use
uvx <tool>(alias foruv tool run) to run tools ephemerally without installing them globally. - Prefer project workflow (
uv add,uv sync) for new work, and runuv lockwhen re-locking after manualpyproject.tomlchanges.
More from liatrio-labs/ai-prompts
git-commit-conventional
Create Conventional Commit messages and execute safe git commits from working tree changes. Use when users ask to create a commit, write a conventional commit message, split broad changes into multiple commits, stage only parts of files, run pre-commit before committing, or perform a quick commit-time quality review with severity guardrails.
24create-pull-request
Generate a reviewer-ready pull request or merge request title and description from branch changes. Use when a user asks to draft PR/MR content, summarize branch deltas against a base branch, or optionally create the PR with gh/glab after approval.
23create-mermaid-diagrams
Create, validate, and repair Mermaid diagrams for technical documentation with a deterministic CLI feedback loop. Use when an AI needs to create Mermaid diagrams, improve Mermaid diagram quality, validate Mermaid fences in markdown, diagnose Mermaid rendering failures, or fix Mermaid syntax and formatting issues.
21liatrio-brand-guidelines
Applies Liatrio brand guidelines to UI design, brand audits, and asset selection. Use when users request Liatrio styling, logo variants, typography or color decisions, visual polish, or formal brand compliance checks.
21branch-surgery-pr-split
Split oversized or mixed-concern branches into smaller, reviewable PR stacks with safety refs, topology selection, parity audits, and merge sequencing. Use when a PR or branch is too large, difficult to review, mixed across concerns, conflict-prone, or needs to be decomposed without losing net changes.
21tilt-dev
Manage local development environments with Tilt. Use when working with projects that run services via Tilt (indicated by presence of Tiltfile), including checking service status, viewing logs, troubleshooting connectivity issues, or managing the Tilt stack. Essential for projects using Tiltfile with local_resource for orchestrating backend, frontend, and other services.
15