Poetry Commands

poetry commands cheatsheet.

Create projects, add dependencies, manage virtual environments, and build and publish — the Poetry commands you reach for every day. Tap to copy.

Project setup
poetry new <name>Scaffold a new project with the standard layout
poetry initCreate a pyproject.toml interactively in the current folder
poetry installInstall dependencies from pyproject.toml and poetry.lock
poetry install --only mainInstall only the main dependencies, skipping dev groups
poetry install --no-devInstall without dev dependencies (Poetry 1.x)
Dependencies
poetry add <pkg>Add a package and install it
poetry add <pkg>@^1.2Add a package with a version constraint
poetry add --group dev <pkg>Add a package to the dev dependency group
poetry remove <pkg>Remove a package and update the lockfile
poetry updateUpdate dependencies to the latest allowed versions
poetry lockResolve dependencies and refresh poetry.lock
Environments
poetry run <cmd>Run a command inside the project's virtualenv
poetry shellSpawn a shell within the virtual environment
poetry env infoShow information about the active environment
poetry env use python3.11Use a specific Python version for the venv
poetry env listList the virtualenvs for the project
Build & publish
poetry buildBuild source and wheel distributions
poetry publishUpload the package to PyPI
poetry version patchBump the patch version in pyproject.toml
poetry version minorBump the minor version in pyproject.toml
poetry version majorBump the major version in pyproject.toml
poetry checkValidate the pyproject.toml configuration
Info
poetry showList installed packages
poetry show --treeShow the dependency tree
poetry show --outdatedList packages with newer versions available
poetry --versionPrint the installed Poetry version

What Poetry actually does

Poetry is a dependency manager and packaging tool for Python that ties everything into a single file: pyproject.toml. It lists your dependencies, records project metadata, and replaces the older scatter of requirements.txt, setup.py and setup.cfg. When you clone a project, a single poetry install reads that file, resolves a consistent set of versions, writes them to poetry.lock, and installs them into a dedicated virtual environment — no manual venv juggling required.

Adding dependencies the right way

Adding packages has a few flavours worth understanding. poetry add <pkg> adds a runtime dependency your app needs and installs it immediately. Pin a range with poetry add <pkg>@^1.2 when you care about the version. Tools you only need while developing — test runners, linters, formatters — belong in a group: poetry add --group dev <pkg>. Every add updates both pyproject.toml and the lockfile so the change is reproducible for everyone on the team.

Environments and running code

Poetry creates and manages a virtual environment for each project so your global Python stays clean. Run a one-off command inside it with poetry run <cmd> — for example poetry run pytest — or open an interactive subshell with poetry shell. Point the project at a specific interpreter using poetry env use python3.11, and inspect what you're working with via poetry env info and poetry env list.

Building and publishing

When it's time to ship, poetry build produces source and wheel distributions and poetry publish uploads them to PyPI. Bump the version first with poetry version patch (or minor / major), and run poetry check to validate your pyproject.toml before you release. These pair naturally with the Python commands for running your code and the Git commands for version control.

FAQ

How do I activate the Poetry virtual environment?
Run poetry shell to spawn a subshell inside the project's virtual environment, or prefix a single command with poetry run — for example poetry run python app.py — to run it in the environment without activating a shell.
What is poetry.lock for?
poetry.lock records the exact resolved version of every dependency so that installs are reproducible. Commit it to version control, and run poetry install to install those pinned versions or poetry lock to regenerate it after changing pyproject.toml.

More cheatsheets