LinuxCommandLibrary

uv-add

Add users to UV user accounts

TLDR

Add the latest version of a package

$ uv add [package]
copy

Add multiple packages
$ uv add [package1 package2 ...]
copy

Add a package with a version requirement
$ uv add [package>=1.2.3]
copy

Add packages to an optional dependency group, which will be included when published
$ uv add --optional [optional] [package1 package2 ...]
copy

Add packages to a local group, which will not be included when published
$ uv add --group [group] [package1 package2 ...]
copy

Add packages to the dev group, shorthand for --group dev
$ uv add --dev [package1 package2 ...]
copy

Add package as editable
$ uv add --editable [path/to/package]/
copy

Enable an extra when installing package, may be provided multiple times
$ uv add [package] --extra [extra_feature]
copy

SYNOPSIS

uv add [OPTIONS] ...

PARAMETERS

...
    The name(s) of the package(s) to add, e.g., 'requests', 'django==4.2', 'numpy>=1.20'.

--raw-requirement
    Add an explicit raw requirement string, allowing for more complex specifications like 'requests[security]>=2.31.0,<3'.

--dev
    Adds the specified package(s) as development-only dependencies.

--optional
    Adds the package(s) as an optional dependency within a specified named group.

--python
    Specifies the path to the Python interpreter to use for the operation.

--index-url
    Sets the base URL of the Python package index to use (defaults to PyPI).

--extra-index-url
    Provides additional URLs for Python package indexes to search.

--no-index
    Ignores all package indexes, only using local paths or specified find-links.

--offline
    Performs the operation entirely offline, using only cached packages.

--upgrade
    Upgrades existing packages to their latest compatible versions during the add operation.

--upgrade-all
    Upgrades all packages in the environment to their latest compatible versions.

--dry-run
    Simulates the addition of packages without making any actual modifications to the environment or configuration files.

--quiet
    Suppresses most output during the command execution.

--verbose
    Enables verbose output, providing more detailed information about the operation.

DESCRIPTION

The command uv add (often mistakenly referred to as 'uv-add') is a subcommand of the uv Python package manager. uv is a modern, extremely fast, and efficient tool for managing Python project dependencies, serving as a drop-in replacement for common operations found in tools like pip, pip-tools, and parts of Poetry or PDM.

The uv add command is specifically used to add new package dependencies to a Python project. It automatically updates the pyproject.toml file (specifically the [project.dependencies] or relevant sections) and manages the corresponding virtual environment. It handles package resolution, downloading, and installation with high performance, leveraging Rust-based parallelism and a robust resolver. This command simplifies the process of declaring and maintaining project requirements, making dependency management more streamlined and reliable.

CAVEATS

The command 'uv-add' as a standalone hyphenated command does not exist in standard Linux distributions. This analysis refers to the uv add subcommand of the uv Python package manager. Users should ensure they have uv installed (typically via pipx install uv or pip install uv) before attempting to use this functionality.

uv is a relatively new tool and its features and CLI syntax might evolve. While aiming for compatibility with pip-like behaviors, its internal mechanisms and lockfile format are distinct.

INTEGRATION WITH PYPROJECT.TOML

uv add primarily manages dependencies defined in the pyproject.toml file, adhering to the PEP 621 standard for project metadata. It automatically adds new packages to the [project.dependencies] section or specified optional/development dependency groups, ensuring project requirements are declarative and version-controlled.

PERFORMANCE BENEFITS

One of uv's key advantages, including its add subcommand, is its exceptional speed. Written in Rust, it leverages parallel processing and an optimized dependency resolver to perform operations significantly faster than traditional Python-based tools, making development workflows more efficient, especially in CI/CD environments.

HISTORY

uv is a project developed by Astral, first publicly released in late 2023. It was designed from the ground up in Rust to be a significantly faster alternative to existing Python package management tools like pip, pip-tools, Poetry, and PDM. Its development focuses on speed and correctness, aiming to make Python dependency management a seamless experience. The uv add command, like other uv subcommands, is a core part of its mission to provide a robust, single-tool solution for Python project needs.

SEE ALSO

uv(1), pip(1), poetry(1), pdm(1), venv(1)

Copied to clipboard