uv.lock


Overview

The uv.lock file is a dependency lock file used by the Python packaging ecosystem, particularly in conjunction with the uv tool or similar Python package managers. Its main purpose is to lock down exact versions of dependencies and their sources for a Python project, ensuring reproducible builds and consistent environments across different machines and deployments.

This file specifies:

Such a lock file guarantees that the environment setup is deterministic, reducing "works on my machine" issues and helping with auditing dependency chains.


Detailed Explanation

File Structure and Key Sections

The file is written in a format similar to TOML, structured into tables and arrays with the following key sections:


Top Level Fields


[[package]] Tables

Each [[package]] section describes a single Python package included in the dependency graph. These entries contain:


[package.dev-dependencies] Table

Defines development-only dependencies grouped by purpose, e.g., test. These are packages required during development and testing but not in production.

Example:

[package.dev-dependencies]
test = [
    { name = "hypothesis" },
    { name = "openpyxl" },
    ...
]

[package.metadata] Table

Metadata about the locked packages, including:


Usage and Interaction with the System


Important Implementation Details


Example Excerpt Interpretation

For the package attrs:

[[package]]
name = "attrs"
version = "25.3.0"
source = { registry = "https://mirrors.aliyun.com/pypi/simple" }
sdist = { url = "...attrs-25.3.0.tar.gz", hash = "sha256:..." }
wheels = [
    { url = "...attrs-25.3.0-py3-none-any.whl", hash = "sha256:..." },
]

How This File Interacts With Other Project Files


Mermaid Diagram: Dependency Flowchart

This flowchart illustrates the main conceptual flow of dependency resolution and usage related to the uv.lock file:

flowchart TD
    A[Project Manifest] --> B[Dependency Resolver]
    B --> C[uv.lock File]
    C --> D[Package Installer]
    D --> E[Virtual Environment / Deployment]
    C --> F[Hash Verification]
    F --> D
    E --> G[Application Runtime]

    style C fill:#f9f,stroke:#333,stroke-width:2px
    style F fill:#bbf,stroke:#333,stroke-width:1px

Summary

This file is essential for dependency management, security, and consistent deployment in Python projects using the uv ecosystem or compatible tools.