uv.lock


Overview

The uv.lock file is an automatically generated lock file used by the Python package manager PDM or similar tools that manage Python dependencies. It captures the exact versions and sources of all dependencies required for a Python project, ensuring reproducible builds and consistent environments across different machines and deployments.

This lock file is crucial for:


Structure and Contents

The uv.lock file is formatted as TOML and consists of several key parts:

1. Global Metadata

2. Package Entries

Each package required by the project is listed under a table array [[package]], each including:


Key Implementation Details


Interaction with Other Parts of the System


Usage Example

To use the uv.lock file in a PDM-managed project:

# Install dependencies exactly as specified in uv.lock
pdm install

# Update dependencies and regenerate uv.lock
pdm update

The lock file should be committed to version control to ensure all collaborators and deployment environments use the same dependency versions.


Mermaid Flowchart: Dependency Resolution Workflow

Below is a simplified flowchart representing how the uv.lock file is used in dependency resolution and installation:

flowchart TD
    A[Project Configuration (pyproject.toml)] --> B[Dependency Resolver]
    B --> C[Resolve Dependency Tree]
    C --> D[Generate uv.lock with exact versions, hashes, markers]
    D --> E[Dependency Installer (pdm install)]
    E --> F[Download packages from source URLs]
    F --> G[Verify package integrity via SHA256 hashes]
    G --> H[Install packages into environment]
    H --> I[Reproducible environment setup]

Summary

The uv.lock file is a critical component for Python projects that rely on precise dependency management. It ensures that all packages and their transitive dependencies are locked to specific versions, tailored for the target Python version and platform. This enables consistent and reliable project setups across various environments, reducing "works on my machine" issues and facilitating smooth collaboration and deployment.


Note: The uv.lock file is machine-generated and not intended for manual editing but for version control and automated dependency management workflows.