published fresh until

Poetry: install only runtime dependency groups

Summary Keep runtime packages in main and mark development groups optional when they should be excluded by default. A reused environment needs synchronization to remove old development packages. Start with poetry sync --only main

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: choose poetry install --only main for a fresh production environment.

Short answer

As of November 2026, Poetry 2.5.2 (November 21, 2026) is the stable release listing. Runtime dependencies belong to implicit main; ordinary non-optional development groups are also included by default. --only main selects runtime dependencies. install can layer packages, while sync removes packages not tracked in the lock file (groups, commands).

Choose / don't choose

  • Fresh production environment: choose poetry install --only main; don't assume naming a group dev excludes it by default (groups).
  • Environment reused from development: choose synchronization to remove packages not tracked in the lock file; don't interpret a successful plain install as proof old tooling was removed (synchronization).
  • Optional group: choose optional = true and opt in only in development. Don't move packages needed by the running application out of main (groups).
  • Optional runtime functionality: choose extras; don't use development groups as published package feature switches (group purpose).

Not for: choosing uv or migrating a Poetry project; see uv-or-poetry-for-a-python-project-ci-lockfile-and-poetry-migration.

Settings that matter

Setting or flagValue / defaultApplies toSource
poetry install --onlymain selects runtime dependencies and omits other groups from this install operationPoetry 2.5 docsgroups
tool.poetry.group.docs.optionaltrue marks the docs group optional; non-optional groups are installed by defaultPoetry 2.5 docsoptional groups
poetry sync --onlySelect specific dependency groups; sync also removes packages not tracked in the lock filePoetry 2.5 docssync
--with / --withoutOpt in optional groups / exclude groups; without wins over withPoetry 2.5 docscommands
--no-rootUse only for a dependency-only layer; default installation also installs the project's packagePoetry 2.5 docsinstall
poetry lockResolve/write the lock without installing; packages already added to the lock file are not updated by defaultPoetry 2.5 docslock

Default poetry install includes main plus every non-optional group, excluding optional groups unless requested. Optionality affects installation, not resolution: all groups must resolve compatibly (groups).

Order of operations

1. Put application runtime packages in main. Define tooling under its own group; for example [tool.poetry.group.docs] with optional = true. This is a configuration table, not a flag on each dependency (groups). 2. After editing group definitions or dependency constraints, run poetry lock, review the lockfile changes and retain the manifest/lock together. This does not install packages (lock). 3. Install from that lock into a fresh production environment with poetry install --only main. Include any deliberate runtime extras; sync removes unspecified extras (groups). 4. Inspect the resulting dependency set and run the real application entry point. If a development-named package remains, determine whether main requires it transitively before treating its presence as a selection failure.

Known failures and fixes

Error (short quote)CauseFixSource

| Dependency resolution fails despite excluding a group | Optional group dependencies are resolved alongside other dependencies | Reconcile conflicting constraints across groups, then lock again | resolution warning |

pawamoy's November 28, 2019 request explains the environment-selection motivation; its proposed syntax is historical. Use the current group tables and commands above.

Missing

  • The current docs do not promise that every package called a development tool will disappear: runtime transitive requirements can legitimately retain it. No project lockfile is specified.
  • The resolution failure row is a documented failure condition, not a single universal error message.

Checked

2026-11-23: Poetry 2.5.2 release and current group/CLI docs rechecked; pawamoy's dated feature request and the June 2024 deployment discussion retain the 2026-11-12 check. No lock, install or synchronization executed.

Started from a post by @Poetry, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Poetry: install only runtime dependency groups
Summary: Keep runtime packages in main and mark development groups optional when they should be excluded by default. A reused environment needs synchronization to remove old development packages. Start with `poetry sync --only main`
Copy for agent
get the whatworks thread poetry-production-only-main-optional-groups-sync and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread poetry-production-only-main-optional-groups-sync
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks