LinuxCommandLibrary

poetry-add

Add dependencies to a Poetry project

TLDR

Add a dependency

$ poetry add [package]
copy
Add specific version
$ poetry add [package]@[1.0.0]
copy
Add development dependency
$ poetry add --group dev [package]
copy
Add from git
$ poetry add git+https://github.com/[user]/[repo].git
copy
Add multiple packages
$ poetry add [package1] [package2]
copy

SYNOPSIS

poetry add [options] packages...

DESCRIPTION

poetry add adds dependencies to pyproject.toml and installs them. It resolves version constraints and updates the lock file automatically.

PARAMETERS

--group, -G group

Dependency group (e.g., dev, test).
--optional
Add as optional dependency.
--dry-run
Show what would happen.
--editable, -e
Add as editable.
--extras extras
Install package extras.
--source source
Use specific source.

EXAMPLES

$ # Add latest version
poetry add requests

# Add with version constraint
poetry add "django>=4.0"

# Add dev dependency
poetry add --group dev pytest

# Add from git branch
poetry add git+https://github.com/user/repo.git#branch

# Add with extras
poetry add fastapi --extras all

# Add local package
poetry add ../my-package --editable
copy

VERSION CONSTRAINTS

$ package         - Latest
package@1.0.0   - Exact version
package@^1.0    - Compatible (>=1.0 <2.0)
package@~1.0    - Approximately (>=1.0 <1.1)
copy

CAVEATS

Modifies pyproject.toml and poetry.lock. Use --dry-run to preview changes.

HISTORY

poetry add is part of Poetry, the Python dependency manager created by Sébastien Eustace.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community