Skip to content

Instantly share code, notes, and snippets.

@souhaiebtar
Created July 21, 2025 08:29
Show Gist options
  • Save souhaiebtar/6e159a152cafdd022d7ba8c334d071e9 to your computer and use it in GitHub Desktop.
Save souhaiebtar/6e159a152cafdd022d7ba8c334d071e9 to your computer and use it in GitHub Desktop.
[uv tool python] uv tool python cheat sheet #python

Install only the dev group (without base dependencies):

uv sync --only-group dev Install multiple groups at once:

uv sync --group dev --group prod Install all groups:

uv sync --all-groups


uv lock Purpose: Creates or updates the lock file (uv.lock)

uv lock # Lock all dependencies uv lock --upgrade # Update to latest compatible versions uv lock --upgrade-package django # Update only specific package


uv sync Purpose: Installs dependencies into your virtual environment

uv sync # Install base dependencies uv sync --group dev # Install base + dev dependencies uv sync --all-groups # Install all dependency groups


Key Difference:

uv lock = resolve dependencies (creates lock file) uv sync = install dependencies (uses lock file)

This separation allows for better control over when dependency resolution happens versus when installation occurs.


To update uv.lock to exclude dev dependencies, you have a few options:

Option 1: Lock without dev group (Recommended) uv lock --no-dev This will resolve and lock only the base dependencies and any production groups, excluding the dev group.

Option 2: Lock only specific groups uv lock --only-group prod This locks only the prod group dependencies (plus base dependencies).

Option 3: Lock base dependencies only uv lock --no-group dev This explicitly excludes the dev group from the lock resolution.

Alternative Approach - Multiple Lock Files: Some teams prefer maintaining separate lock files for different environments:

Create production lock file

uv lock --no-dev --output-file uv.prod.lock

Create development lock file (default)

uv lock Then use them accordingly:

For production

uv sync --frozen --lock-file uv.prod.lock

For development

uv sync --group dev

After updating the lock file:

uv sync # This will now install only the dependencies in the updated lock file

The most common scenario is using uv lock --no-dev when preparing for production deployment where you don't want development tools included.


To uninstall dev dependencies using uv, you have several approaches:

Option 1: Sync without dev group (Recommended) uv sync Since your pyproject.toml has default-groups = [], this will:

Install only base dependencies (Django) Automatically remove any packages not in the current sync (including dev dependencies) Option 2: Explicitly sync without dev group uv sync --no-group dev This explicitly excludes the dev group and removes any dev dependencies that were previously installed.

Option 3: Sync only production dependencies uv sync --group prod This will install base dependencies + prod group, and remove everything else (including dev dependencies).

Option 4: Remove specific packages manually uv remove ruff # Remove the specific dev dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment