Poetry

Poetry

Install Poetry

curl -sSL https://install.python-poetry.org | python3 -

Or

pip install poetry

Config Poetry

poetry config --list
!poetry config --list
cache-dir = "/home/ben/.cache/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/ben/.cache/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true
!poetry config virtualenvs.in-project true

Initallise Poetry

poetry init

Managing Dependencies

poetry add requests

Managing Development Dependencies

poetry add --dev pytest

Updating Dependencies

poetry update

Managing Virtual Environments

poetry install

Activating the Virtual Environment

poetry shell

Deactivating the Virtual Environment

exit

Running Scripts and Commands

You can run scripts or commands within the Poetry-managed environment without activating it explicitly:

poetry run python my_script.py

Publishing Packages

poetry build  # Builds the package
poetry publish  # Publishes the package to PyPI

Exporting to requirements.txt

poetry self add poetry-plugin-export
poetry export -f requirements.txt -o requirements.txt --without-hashes
Back to top