UV Package Manager

UV Package Manager

Teaches an AI agent to use the uv package manager for fast Python dependencies, virtual environments, lockfiles, Docker builds and migration from pip or poetry.

Skill files2 files

references/

SKILL.md346 lines
1
---
2
name: uv-package-manager
3
description: Master the uv package manager for fast Python dependency management, virtual environments, and modern Python project workflows. Use when setting up Python projects, managing dependencies, or optimizing Python development workflows with uv.
4
---
5
6
# UV Package Manager
7
8
Comprehensive guide to using uv, an extremely fast Python package installer and resolver written in Rust, for modern Python project management and dependency workflows.
9
10
## When to Use This Skill
11
12
- Setting up new Python projects quickly
13
- Managing Python dependencies faster than pip
14
- Creating and managing virtual environments
15
- Installing Python interpreters
16
- Resolving dependency conflicts efficiently
17
- Migrating from pip/pip-tools/poetry
18
- Speeding up CI/CD pipelines
19
- Managing monorepo Python projects
20
- Working with lockfiles for reproducible builds
21
- Optimizing Docker builds with Python dependencies
22
23
## Core Concepts
24
25
### 1. What is uv?
26
27
- **Ultra-fast package installer**: 10-100x faster than pip
28
- **Written in Rust**: Leverages Rust's performance
29
- **Drop-in pip replacement**: Compatible with pip workflows
30
- **Virtual environment manager**: Create and manage venvs
31
- **Python installer**: Download and manage Python versions
32
- **Resolver**: Advanced dependency resolution
33
- **Lockfile support**: Reproducible installations
34
35
### 2. Key Features
36
37
- Blazing fast installation speeds
38
- Disk space efficient with global cache
39
- Compatible with pip, pip-tools, poetry
40
- Comprehensive dependency resolution
41
- Cross-platform support (Linux, macOS, Windows)
42
- No Python required for installation
43
- Built-in virtual environment support
44
45
### 3. UV vs Traditional Tools
46
47
- **vs pip**: 10-100x faster, better resolver
48
- **vs pip-tools**: Faster, simpler, better UX
49
- **vs poetry**: Faster, less opinionated, lighter
50
- **vs conda**: Faster, Python-focused
51
52
## Installation
53
54
### Quick Install
55
56
```bash
57
# Using Homebrew (macOS or Linux)
58
brew install uv
59
60
# Using Cargo (if you have Rust)
61
cargo install --locked uv
62
```
63
64
On Windows, use WinGet:
65
66
```powershell
67
winget install --id=astral-sh.uv -e
68
```
69
70
Use the [official installation guide](https://docs.astral.sh/uv/getting-started/installation/)
71
for other supported installation methods.
72
73
### Verify Installation
74
75
```bash
76
uv --version
77
# uv 0.x.x
78
```
79
80
## Quick Start
81
82
### Create a New Project
83
84
```bash
85
# Create new project with virtual environment
86
uv init my-project
87
cd my-project
88
89
# Or create in current directory
90
uv init .
91
92
# Initialize creates:
93
# - .python-version (Python version)
94
# - pyproject.toml (project config)
95
# - README.md
96
# - .gitignore
97
```
98
99
### Install Dependencies
100
101
```bash
102
# Install packages (creates venv if needed)
103
uv add requests pandas
104
105
# Install dev dependencies
106
uv add --dev pytest black ruff
107
108
# Install from requirements.txt
109
uv pip install -r requirements.txt
110
111
# Install from pyproject.toml
112
uv sync
113
```
114
115
## Virtual Environment Management
116
117
### Pattern 1: Creating Virtual Environments
118
119
```bash
120
# Create virtual environment with uv
121
uv venv
122
123
# Create with specific Python version
124
uv venv --python 3.12
125
126
# Create with custom name
127
uv venv my-env
128
129
# Create with system site packages
130
uv venv --system-site-packages
131
132
# Specify location
133
uv venv /path/to/venv
134
```
135
136
### Pattern 2: Activating Virtual Environments
137
138
```bash
139
# Linux/macOS
140
source .venv/bin/activate
141
142
# Windows (Command Prompt)
143
.venv\Scripts\activate.bat
144
145
# Windows (PowerShell)
146
.venv\Scripts\Activate.ps1
147
148
# Or use uv run (no activation needed)
149
uv run python script.py
150
uv run pytest
151
```
152
153
### Pattern 3: Using uv run
154
155
```bash
156
# Run Python script (auto-activates venv)
157
uv run python app.py
158
159
# Run installed CLI tool
160
uv run black .
161
uv run pytest
162
163
# Run with specific Python version
164
uv run --python 3.11 python script.py
165
166
# Pass arguments
167
uv run python script.py --arg value
168
```
169
170
## Package Management
171
172
### Pattern 4: Adding Dependencies
173
174
```bash
175
# Add package (adds to pyproject.toml)
176
uv add requests
177
178
# Add with version constraint
179
uv add "django>=4.0,<5.0"
180
181
# Add multiple packages
182
uv add numpy pandas matplotlib
183
184
# Add dev dependency
185
uv add --dev pytest pytest-cov
186
187
# Add optional dependency group
188
uv add --optional docs sphinx
189
190
# Add from git
191
uv add git+https://github.com/user/repo.git
192
193
# Add from git with specific ref
194
uv add git+https://github.com/user/repo.git@v1.0.0
195
196
# Add from local path
197
uv add ./local-package
198
199
# Add editable local package
200
uv add -e ./local-package
201
```
202
203
### Pattern 5: Removing Dependencies
204
205
```bash
206
# Remove package
207
uv remove requests
208
209
# Remove dev dependency
210
uv remove --dev pytest
211
212
# Remove multiple packages
213
uv remove numpy pandas matplotlib
214
```
215
216
### Pattern 6: Upgrading Dependencies
217
218
```bash
219
# Upgrade specific package
220
uv add --upgrade requests
221
222
# Upgrade all packages
223
uv sync --upgrade
224
225
# Upgrade package to latest
226
uv add --upgrade requests
227
228
# Show what would be upgraded
229
uv tree --outdated
230
```
231
232
### Pattern 7: Locking Dependencies
233
234
```bash
235
# Generate uv.lock file
236
uv lock
237
238
# Update lock file
239
uv lock --upgrade
240
241
# Lock without installing
242
uv lock --no-install
243
244
# Lock specific package
245
uv lock --upgrade-package requests
246
```
247
248
## Python Version Management
249
250
### Pattern 8: Installing Python Versions
251
252
```bash
253
# Install Python version
254
uv python install 3.12
255
256
# Install multiple versions
257
uv python install 3.11 3.12 3.13
258
259
# Install latest version
260
uv python install
261
262
# List installed versions
263
uv python list
264
265
# Find available versions
266
uv python list --all-versions
267
```
268
269
### Pattern 9: Setting Python Version
270
271
```bash
272
# Set Python version for project
273
uv python pin 3.12
274
275
# This creates/updates .python-version file
276
277
# Use specific Python version for command
278
uv --python 3.11 run python script.py
279
280
# Create venv with specific version
281
uv venv --python 3.12
282
```
283
284
## Project Configuration
285
286
### Pattern 10: pyproject.toml with uv
287
288
```toml
289
[project]
290
name = "my-project"
291
version = "0.1.0"
292
description = "My awesome project"
293
readme = "README.md"
294
requires-python = ">=3.8"
295
dependencies = [
296
"requests>=2.31.0",
297
"pydantic>=2.0.0",
298
"click>=8.1.0",
299
]
300
301
[project.optional-dependencies]
302
dev = [
303
"pytest>=7.4.0",
304
"pytest-cov>=4.1.0",
305
"black>=23.0.0",
306
"ruff>=0.1.0",
307
"mypy>=1.5.0",
308
]
309
docs = [
310
"sphinx>=7.0.0",
311
"sphinx-rtd-theme>=1.3.0",
312
]
313
314
[build-system]
315
requires = ["hatchling"]
316
build-backend = "hatchling.build"
317
318
[tool.uv]
319
dev-dependencies = [
320
# Additional dev dependencies managed by uv
321
]
322
323
[tool.uv.sources]
324
# Custom package sources
325
my-package = { git = "https://github.com/user/repo.git" }
326
```
327
328
### Pattern 11: Using uv with Existing Projects
329
330
```bash
331
# Migrate from requirements.txt
332
uv add -r requirements.txt
333
334
# Migrate from poetry
335
# Already have pyproject.toml, just use:
336
uv sync
337
338
# Export to requirements.txt
339
uv pip freeze > requirements.txt
340
341
# Export with hashes
342
uv pip freeze --require-hashes > requirements.txt
343
```
344
345
For advanced workflows including Docker integration, lockfile management, performance optimization, tool comparison, common workflows, tool integration, troubleshooting, best practices, migration guides, and command reference, see [references/advanced-patterns.md](references/advanced-patterns.md)
346

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,341 prompts

More by @OpenSourceBuffGuy

See all
Walking POV down station steps onto a seaside train prompt image

Walking POV down station steps onto a seaside train

Generates a one-take first-person POV video of a morning commute in coastal Japan: station stairs, a stroked orange cat, a window seat and rails running beside the sea.

video-prompt, pov, single-take, vlog, timed-beats, handheld, japan, photorealistic, natural-light, ocean, animals, seedance, sound-effects, travel, cityscape, widescreen, camera-movement, long-form, negative-prompt

Kitten knight shields dragon egg in snowstorm prompt image

Kitten knight shields dragon egg in snowstorm

Directs a 24-second live-action fantasy short in which an armoured kitten shields a dragon egg in a snowstorm, with five timed scenes and a consistency block.

video-prompt, timed-beats, multi-shot, fantasy-world, creatures, animals, winter, character-consistency, cinematic, photorealistic, negative-prompt, guardrails, camera-movement, golden-hour, seedance, short-film, warriors, dramatic-lighting, long-form, shallow-depth-of-field

Smiling woman with ice cream by beach huts prompt image

Smiling woman with ice cream by beach huts

Draws a photorealistic 9:16 lifestyle portrait of a smiling woman with an ice cream cone on a pastel beach-hut promenade in golden-hour light.

image-prompt, nano-banana, portrait, woman, summer, golden-hour, natural-light, bokeh, vertical-format, photorealistic, medium-shot, fashion, vibrant-colors, pastel, ocean, soft-lighting, jewelry, for-photographers, for-content-creators

Reviews

Loading reviews…

Discussion

Loading comments…