Page content


Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Install OpenBSD

… and update path

pip install --user poetry

cat <<'EOF'>> ~/.profile

# Poetry
export PATH=$PATH:~/.local/bin

. ~/.profile

ev install as root ?

doas pip install --user poetry

cat <<'EOF'>> ~/.profile

# Poetry
export PATH=$PATH:/root/.local/bin

. ~/.profile

Install Debian

sudo su -
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -

Basic Usage

$ poetry --version
Poetry version 1.1.11

$ poetry self update
You are using the latest version

$ poetry self update --preview
Updating to 1.2.0a2


  Could not find poetry-1.2.0a2-linux.sha256sum file

  at ~/.poetry/lib/poetry/console/commands/self/update.py:260 in _update
      256│         try:
      257│             r = urlopen(base_url + "/{}/{}".format(version, checksum))
      258│         except HTTPError as e:
      259│             if e.code == 404:
    → 260│                 raise RuntimeError("Could not find {} file".format(checksum))
      262│             raise
      264│         checksum = r.read().decode().strip()

# Downgrade
$ poetry self update 0.8.0

poetry new

$ poetry new poetry-demo
Created package poetry_demo in poetry-demo

$ tree poetry-demo/
├── poetry_demo
│   └── __init__.py
├── pyproject.toml
├── README.rst
└── tests
    ├── __init__.py
    └── test_poetry_demo.py

2 directories, 5 files

or if you have an existing project, you can do the poetry init

poetry init

$ poetry init

This command will guide you through creating your pyproject.toml config.

Package name [test]:
Version [0.1.0]:
Description []:  just a little test
Author [None, n to skip]:  That's Me
License []:
Compatible Python versions [^3.9]:

Would you like to define your main dependencies interactively? (yes/no) [yes]
You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Search for package to add (or leave blank to continue):

Would you like to define your development dependencies interactively? (yes/no) [yes]
Search for package to add (or leave blank to continue):

Generated file

name = "test"
version = "0.1.0"
description = "just a little test"
authors = ["That's Me"]

python = "^3.9"


requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Do you confirm generation? (yes/no) [yes]

poetry add

$ poetry add pendulum
Creating virtualenv test-nWsx-QRW-py3.9 in /home/stoege/.cache/pypoetry/virtualenvs
Using version ^2.1.2 for pendulum

Updating dependencies
Resolving dependencies... (0.5s)

Writing lock file

Package operations: 4 installs, 0 updates, 0 removals

  • Installing six (1.16.0)
  • Installing python-dateutil (2.8.2)
  • Installing pytzdata (2020.1)
  • Installing pendulum (2.1.2)

poetry show tree

$ poetry show --tree
pendulum 2.1.2 Python datetimes made easy
├── python-dateutil >=2.6,<3.0
│   └── six >=1.5
└── pytzdata >=2020.1

poetry show –latest

$ poetry show --latest
pendulum        2.1.2  2.1.2  Python datetimes made easy
python-dateutil 2.8.2  2.8.2  Extensions to the standard Python datetime module
pytzdata        2020.1 2020.1 The Olson timezone database for Python.
six             1.16.0 1.16.0 Python 2 and 3 compatibility utilities

poetry build

$ poetry build
Building test (0.1.0)


  No file/folder found for package test

  at ~/.poetry/lib/poetry/_vendor/py3.9/poetry/core/masonry/utils/module.py:63 in __init__
       59│                             "from": str(src.relative_to(self._path)),
       60│                         }
       61│                     ]
       62│                 else:
    →  63│                     raise ModuleOrPackageNotFound(
       64│                         "No file/folder found for package {}".format(name)
       65│                     )
       67│         for package in packages:

poetry publish

$ poetry publish
No files to publish. Run poetry build first or use the --build option.

set python version

poetry env use $(which python3.9)

-> pyproject.toml -> python = "^3.9"

Use an Existing requirements.txt File

$ cat requirements.txt

$ poetry add `cat requirements.txt`
Creating virtualenv rp-require-0ubvZ-py3.9 in ~/Library/Caches/pypoetry/virtualenvs

Updating dependencies
Resolving dependencies... (6.2s)

Writing lock file

Package operations: 7 installs, 0 updates, 0 removals

  • Installing certifi (2020.12.5)
  • Installing chardet (4.0.0)
  • Installing idna (2.10)


awk -F '==' '{print $1}' requirements.txt | xargs -n1 poetry add

Create requirements.txt From poetry.lock

$ poetry export --output requirements.txt

Command Reference

$ poetry --version  Show the version of your Poetry installation.
$ poetry new          Create a new Poetry project.
$ poetry init         Add Poetry to an existing project.
$ poetry run          Execute the given command with Poetry.
$ poetry add          Add a package to pyproject.toml and install it.
$ poetry update       Update your project’s dependencies.
$ poetry install      Install the dependencies.
$ poetry show         List installed packages.
$ poetry lock         Pin the latest version of your dependencies into poetry.lock.
$ poetry lock --no-update   Refresh the poetry.lock file without updating any dependency version.
$ poetry check        Validate pyproject.toml.
$ poetry config --list      Show the Poetry configuration.
$ poetry env list     List the virtual environments of your project.
$ poetry export       Export poetry.lock to other formats.

sha256: dd082caac3ae7b25baf8894df57d2e1da976d8c940d3d53da116c78f1cb716a4