Making Python packages with poetry

About Poetry, a tool to install, manage and create packages in Python.

Poetry is a tool for creating, managing and publishing packages in Python.


May be installed from PyPI or using a script.

I prefer the PyPI version because I've heard people warning against getting accustomed to running scripts that you don't know.


We can use pip to install poetry from PyPI.

pip install poetry


Download the installation script with curl and use Python to run it.

curl -sSL | python -

Poetry's website recommends this method of installation as

If installed using this method, a sub command of poetry itself can be used to update it independent of Python version.

Create a project

poetry new project-name

By default the project created using poetry would have a flat layout.

If you prefer a src-layout, use the --src option and do

poetry new --src project-name

See [docs](

Pre-existing project

The new sub-command is used when we start a new package from scratch. If you already got the files, you may use the init sub-command to generate the pyproject.toml file.

poetry init

Add dependency packages

poetry add package-name

A package can be installed as a development dependency using the --dev or -D option as in

poetry add -D package-name


Build your package with

poetry build

and the built module's files would appear under the dist/ directory.


You may want to adjust the remote server to which the package is published with

poetry config repositories.pypi ""   # for

The built module can be pushed to a remote server with

poetry publish

by default the remote server is

The package can be both built and published with

poetry --build publish