curl -sSL https://install.python-poetry.org | python3 -★Official installer — puts Poetry in its own venv, off your project's PATH.pipx install poetry★Clean alternative if you already use pipx. Also on Homebrew, conda-forge.pip install poetry # inside your project venvAvoid — Poetry's own deps can clash with your project's. Keep it separate.poetry self updateUpgrade Poetry itself (installer/pipx installs).poetry --version·poetry aboutConfirm the version — this sheet assumes 2.x.
poetry new myapp★Scaffold a fresh project:src/layout,tests/, README, PEP 621pyproject.toml.poetry new --flat myappPackage at the top level instead of undersrc/.poetry initInteractively add apyproject.tomlto an existing codebase.poetry init --no-interactionNon-interactive — good for scripts/CI scaffolding.poetry checkValidatepyproject.tomland its consistency with the lock.--lockto focus on drift.
poetry add httpx★Resolve, write to[project].dependencies+poetry.lock, install — all at once.poetry add "httpx>=0.27,<1.0"Any PEP 508 spec. Bareaddwrites a caret-style>=0.28,<0.29bound.poetry add --group dev pytest ruff★Into a group (2.x:-G). Replaces the old--devflag.2.xpoetry add "httpx[socks]"With extras.-E/--extrasalso works.poetry add --editable ../mylibLocal path, editable. Alsogit+https://...,--source,--optional.poetry add --dry-run numpyPreview the resolution without changing anything.
poetry remove httpx★Drop from pyproject + lock + env.--group devto target a group.poetry update★Re-resolve to the newest versions your constraints allow; refresh the lock.poetry update httpx anyioUpdate only named packages, leave the rest pinned.poetry update --with dev --dry-runPreview an update including a group.add/update change the lock; sync doesn'tadd/updatere-resolve.install/syncapply the existing lock.
[dependency-groups]★
dev = ["pytest (>=9,<10)"]Groups now use the standard PEP 735 table. Not shipped to your users.PEP 735[tool.poetry.group.docs.dependencies]
sphinx = "^8"The Poetry-specific group form — still valid, needed for Poetry-only features.poetry install --with docs★Include an optional group.--without devto skip one.poetry install --only main★Runtime deps only — the lean production/CI install.--only devfor just tools.optional = true # under a groupA group installed only when explicitly requested with--with.
[project.optional-dependencies]★
fast = ["orjson"]Extras ship with your package — users opt in viapip install pkg[fast].PEP 621poetry install --extras "fast"Install your own extras locally.--all-extrasfor all of them.groups = dev-time; extras = ship-time★The key distinction: groups never reach your users; extras are part of the published package.poetry install --all-groupsEvery dependency group at once.
[project] # PEP 621★Standard metadata: name, version,requires-python,dependencies. Commit.2.x[tool.poetry]★Poetry-only bits:packages,[tool.poetry.source],requires-poetry. Not deprecated.poetry.lock★Exact resolution + hashes + locked markers/groups. Commit it. Never hand-edit.[build-system]requires = ["poetry-core>=2.0"]. 2.1+ respects any PEP 517 backend here.2.1virtualenv is NOT in the projectBy default it lives in Poetry's cache, not.venv. Setin-projectto change that.