LinuxCommandLibrary

poetry-export

Export project dependencies to requirements file

TLDR

Export dependencies to a requirements.txt file

$ poetry export [[-o|--output]] [requirements.txt]
copy

Export dependencies including development dependencies
$ poetry export [[-o|--output]] [requirements-dev.txt] --dev
copy

Export dependencies without hashes
$ poetry export [[-o|--output]] [requirements.txt] --without-hashes
copy

Export dependencies for a specific format
$ poetry export [[-o|--output]] [requirements.txt] [[-f|--format]] [requirements.txt]
copy

Export only specific dependency groups
$ poetry export [[-o|--output]] [requirements.txt] --only [main]
copy

Display help
$ poetry export [[-h|--help]]
copy

SYNOPSIS

poetry export [options]

PARAMETERS

-f, --format FORMAT
    Specifies the format for the exported dependencies.
Common formats include requirements.txt and pip-compile.

-o, --output OUTPUT
    Defines the path and filename for the exported output.
If omitted, the output is printed to stdout.

--dev
    Includes development dependencies in the exported output.
By default, only production dependencies are exported.

--without-hashes
    Omits the package hashes from the exported file.
This can be useful for environments where hashes are not supported
or when they cause issues (e.g., older pip versions).

--extras EXTRAS
    Exports specific dependency 'extras' defined in pyproject.toml.
Can be specified multiple times for multiple extras.

--all-extras
    Includes all defined 'extras' in the exported dependency list.

--groups GROUPS
    Specifies one or more dependency groups to explicitly include in the export.
Can be used multiple times.

--only ONLY
    Exclusively exports dependencies from the specified groups,
ignoring all other groups (including main and dev if not specified).

--without WITHOUT
    Excludes one or more dependency groups from the export.

--with WITH
    Explicitly includes one or more dependency groups in the export.
Useful when combined with --only to specify inclusions.

--without-reference
    Does not include a comment referencing the original Poetry project
at the top of the exported file.

DESCRIPTION

The poetry export command is a crucial tool within the
Poetry dependency manager, designed to bridge the gap between
Poetry's sophisticated dependency resolution and traditional
Python package management workflows. It takes the dependencies
defined in your pyproject.toml file and precisely pinned
in your poetry.lock file, then generates a list of these
dependencies in various formats suitable for other tools.

The primary use case is to create a requirements.txt file,
which is widely recognized by pip and other deployment systems.
This allows projects managed by Poetry to be easily deployed to
environments that might not have Poetry installed, such as CI/CD
pipelines, Docker containers, or production servers.
poetry export ensures reproducibility by always using the
exact versions specified in the poetry.lock file.

It supports exporting development dependencies, excluding
package hashes for simpler environments, and handling
project extras. This flexibility makes it indispensable for
maintaining a clean separation of concerns between development
and deployment dependency sets.

CAVEATS

Using poetry export requires an existing pyproject.toml
file with defined dependencies and a corresponding poetry.lock
file, which must be up-to-date. If the poetry.lock file is
missing or outdated, Poetry may prompt to run poetry install
first or resolve dependencies implicitly. The command strictly
relies on the lock file for exact versions, ensuring reproducibility.
It only handles Python package dependencies and does not manage
system-level dependencies or non-Python requirements.

USAGE EXAMPLES

Export basic requirements:
poetry export -o requirements.txt

Export with development dependencies:
poetry export --dev -o dev-requirements.txt

Export without package hashes:
poetry export --without-hashes -o no-hash-requirements.txt

Export specific groups (e.g., 'main' and 'test'):
poetry export --groups main --groups test -o requirements-with-tests.txt

Export only specific groups (e.g., 'main'):
poetry export --only main -o production-only.txt

HISTORY

The poetry export command has been a fundamental feature of
the Poetry dependency manager since its early development by
Sébastien Eustace. Its inception was driven by the need to integrate
Poetry-managed projects into traditional Python environments
that primarily rely on pip and requirements.txt files.

Over time, it has evolved alongside Poetry itself, gaining
new options for fine-grained control over exported dependencies,
such as explicit handling of development dependencies, dependency
groups, and the inclusion/exclusion of package hashes. This
continuous refinement ensures that poetry export remains
a robust and flexible tool for various deployment scenarios.

SEE ALSO

poetry add(1), poetry install(1), pip freeze(1), pip install(1), pip-compile(1) (from pip-tools)

Copied to clipboard