Skip to content
The Chat Archive
claude-sonnet-4-20250514· Anthropic LMArena Human Preference 140K

How do I add a package to an optional-dependency with uv add?

  1. User

    How do I add a package to an optional-dependency with uv add?

  2. Assistant

    You can add a package as an optional dependency using the --optional flag with uv add. The syntax is:

    uv add --optional <group-name> <package-name>
    

    For example:

    uv add --optional dev pytest
    uv add --optional docs sphinx
    uv add --optional testing coverage
    

    This will add the package to the specified optional dependency group in your pyproject.toml file. The optional dependencies will appear under [project.optional-dependencies] like:

    [project.optional-dependencies]
    dev = ["pytest"]
    docs = ["sphinx"]
    testing = ["coverage"]
    

    To install optional dependencies later, you can use:

    uv sync --extra dev
    # or
    uv install --extra dev
    

    You can also install multiple optional groups at once:

    uv sync --extra dev --extra testing
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.