Skip to navigation

Python Dependency Groups vs Extras: A Claude Code Migration Map

In short: Classify runtime, optional-feature and development requirements before moving a Python project to dependency groups.

Published 21 min read
On this page

Direct answer

Dependency groups and extras solve different problems, so the migration is a classification job before it is an edit. Groups hold requirements you need locally, such as test runners, linters and type checkers. Extras stay the mechanism for optional runtime features a consumer can request. A packaging specification rule says build backends must not include dependency group data in built distributions, which is why a group migration leaves the published requirements your consumers see untouched. The concrete win is a manifest where local tooling has its own home and the package’s published contract is easier to read. The concrete loss is that group support differs across the tools your team already runs, so a group declaration can work in one workflow and fail in another until you check each one.

Ask Claude Code to produce a before-and-after table that names each requirement’s destination, not to rewrite pyproject.toml in one pass. The classification decides where a requirement belongs: core runtime, optional feature, or development-only. Once every row has a destination, moving the development-only rows into groups is a small, reviewable change. Anything the package itself imports at runtime stays in core dependencies or an extra, because moving it into a group would stop it reaching people who install the package.

Why the classification is worth an hour

Three failure modes come from mixing the buckets. A development tool listed as a core dependency travels to every consumer and adds install weight they never asked for. A runtime import parked in a dev bucket disappears for consumers and breaks their install at runtime. An optional feature buried in a plain list cannot be requested selectively, so users install code they do not use or skip the feature entirely.

The cost is quiet because none of these are build failures on your machine. Your local environment has everything installed, so tests pass and the linter is happy. The break lands on the consumer’s machine weeks later, or it shows up as a dependency audit that cannot tell tooling from product surface. Classifying before you migrate is cheaper than debugging a missing import on a user’s machine.

There is a revert advantage too. The whole change lives in one manifest file, so a rollback is a single revert with no data migration and no published artifact to retract. Which makes it a good candidate for a Claude Code session: the agent can draft the classification and the edit, and a reviewer can check every moved line against where the package imports it.

Evidence and its limits

Official, F001: The Python Packaging User Guide: Dependency Groups specification says build backends must not include dependency group data in built distributions. The rule is what makes groups safe for local-only tooling. It is a specification rule, and individual tools still need a compatibility check before you rely on their group handling.

Official, F002 support: The guides for writing pyproject.toml and the pyproject.toml specification document where core dependencies and optional dependencies live in the manifest. PEP 735, Dependency Groups in pyproject.toml, defines the group table and its include mechanism.

Official, agent loop: Claude Code best practices recommends giving the agent a check that returns pass or fail. For this migration the check is a build followed by a metadata diff, described in the worked example below. Claude Code common workflows covers iterating on an edit against a command.

Derived, F002: A migration worksheet that classifies each requirement as core runtime, optional feature, or development-only is an editorial workflow built on those packaging distinctions. It is not a normative rule, and your project may have categories this post does not cover.

No claim here depends on a specific installer version, lockfile tool, or CI provider. Tool support for groups is treated as something to verify, not assumed.

What dependency groups solve

Groups answer one question: where do requirements live that the project needs to develop but a consumer does not need to run it. Before groups existed, teams handled this with a requirements file next to the manifest, a dev extra, or a comment telling people what to install by hand. Each of those drifted from the manifest in its own way.

A group is declared inside pyproject.toml under a [dependency-groups] table and has a name plus a list of requirements. Groups can include other groups by name, which lets a team define a base development set and layer project-specific groups on top. Because the group lives in the manifest, it is versioned with the code and travels with the repository.

The specification is explicit that this data is for local development use and must stay out of built distributions. Extras do not have that property. An extra is published metadata: it appears in the distribution’s metadata so a consumer can request it with an install expression. A group is not consumer-facing at all.

Property Core dependencies Optional extras Dependency groups
Where declared project.dependencies project.optional-dependencies [dependency-groups]
Reaches consumers Installed with the package Installed when requested Never
In built distribution metadata Yes Yes No
Can include other groups N/A No Yes, by name
Typical contents Runtime imports Optional feature libraries Test, lint, type, docs tooling

Read the table as a routing rule. A requirement with consumers who need it installed goes in the first two columns. A requirement only your workflow needs goes in the third.

Extras vs groups vs core dependencies in practice

Core dependencies are the requirements the package imports directly. Removing a requirement from the list makes the package fail to import, it belongs in core. This is the only bucket that ships to every consumer unconditionally.

Extras model optional runtime features. A package that can talk to two databases, or that has a accelerated path behind an optional library, exposes each of those as an extra. The consumer chooses. Extra contents are part of the published metadata, so a change to an extra is a change to what the package offers, not a private edit.

Groups model the development workflow. A test runner, a type checker, a formatter, a documentation builder, and a release helper are all workflow tools. None of them is imported by the package at runtime. Moving them into groups makes the split visible in one file instead of spread across a requirements file and tribal knowledge.

The distinction that trips teams is the optional feature that only developers currently use. A consumer who could legitimately request the feature, it is an extra candidate, even if nobody outside the team requests it yet. Where a requirement exists purely so contributors can work on the code, it is a group candidate. The test is who benefits from the requirement, not who currently installs it.

Read the existing pyproject.toml

Start from what the manifest says today, not from memory. Two commands produce the raw material.

bash
python -c "import tomllib,pathlib; d=tomllib.loads(pathlib.Path('pyproject.toml').read_text()); print(list(d.get('project',{}).get('dependencies') or [])); print(list((d.get('project',{}).get('optional-dependencies') or {}).items()))"

If the project keeps a legacy requirements file, diff it against the manifest. Requirements that exist in the file but not the manifest are exactly the drift the migration should remove. The goal at the end of this step is a complete inventory: every requirement the project declares anywhere, in one list with its current home.

A package with a small manifest can be inventoried by eye. A package with several extras and a long requirements file benefits from the script, because the point is to see every requirement once, in one place, before deciding where it goes. Resist the urge to classify while reading; list first, classify second.

Build the requirement classification matrix

The classification matrix is the artifact that makes the migration reviewable. One row per requirement, four columns: name, current home, who needs it, destination.

Requirement Current home Who needs it Destination
requests core Package imports it at runtime core, unchanged
pydantic core Package imports it at runtime core, unchanged
psycopg[binary] extra postgres Consumers who use the Postgres backend extra, unchanged
pytest requirements.txt Contributors running tests group test
mypy requirements.txt Contributors type-checking group types
ruff requirements.txt Contributors linting group lint
sphinx requirements.txt Contributors building docs group docs
build requirements.txt Maintainers cutting releases group release

Three classification rules keep the matrix honest. Anything the package imports belongs in core or an extra, never a group. Anything only contributors import belongs in a group. Anything a consumer could request belongs in an extra, even if the current user base is small.

Watch for the requirements that look like tooling but are not. A package used by the test suite but also imported by a code path the package ships, such as a serialization library used in a maintenance script the package exposes, is runtime. The import search in the next section settles these cases.

Migrate one group at a time

Move the development-only rows into groups one at a time, starting with the group whose membership is least ambiguous. Test tooling is usually the safest first move, because pytest and its plugins are almost never runtime imports.

bash
[dependency-groups]
test = ["pytest>=8", "pytest-cov"]
lint = ["ruff>=0.5"]
types = ["mypy>=1.10"]

[tool.uv]
# example only: confirm your tool's group install flag

Install the group with the tool your team uses and run the workflow it covers. A group that installs but does not run the tests it declares is not finished. The pass condition for each group is: it installs, the workflow it covers runs, and the built distribution metadata is unchanged.

Two properties of groups matter during this step. Groups can include other groups by name, so a dev group that pulls in test, lint and types gives contributors a single install target. Include cycles, where group A includes B and B includes A, are a real hazard, and the review in a later section checks for them.

Claude Code can draft the group blocks from the classification matrix, and the draft needs review. The Claude Code overengineering guide describes how a small request can become a large diff; a group migration is a place where the agent may reformat the whole manifest when the task only needs three new tables. Ask for the group tables as an addition and keep the rest of the file untouched.

Check published metadata separately

The specification rule in F001 says group data stays out of built distributions. Verify that on your own package rather than trusting the rule to a particular backend version.

bash
python -m build
python -c "import zipfile,glob; w=zipfile.ZipFile(glob.glob('dist/*.whl')[0]); print(w.read([n for n in w.namelist() if n.endswith('METADATA')][0]).decode())"

The METADATA file lists Requires-Dist entries for core dependencies and Provides-Extra plus conditional Requires-Dist entries for extras. Group requirements should not appear anywhere in it. A diff of METADATA before and after the migration is the concrete check: it should be empty if you only moved development tooling, and it should show changes only in the extras you deliberately edited.

Keep the metadata check separate from the workflow check. A group that installs and runs does not prove the distribution is unchanged, and an unchanged distribution does not prove the workflow runs. The two checks answer different questions, and the migration is done when both pass.

On the boundary between local workflow and published contract, the same discipline appears in the Claude Code dependency install side effects guide, which covers what happens when a package’s install does more than add files. This post stays on manifest structure and metadata, not on lifecycle scripts or registry trust.

Review the migration diff

The final review is a line-by-line pass over the manifest diff with one question per deleted requirement: does the package import this at runtime? Two defects to catch.

The first defect is a runtime requirement moved into a group. Search the package source for each requirement name that changed buckets. A hit in shipped code means the requirement belongs in core or an extra and must move back. This is the failure that breaks consumers, so it gets the most attention.

The second defect is an optional feature moved into a group. Consumers who could request the feature find code belongs in an extra. Moving it into a group removes the consumer’s ability to select it.

Groups can also include other groups, so read the include graph for cycles.

Group Includes Risk to check
test none Plugin versions still resolve
lint none Config file still matches the tool version
types test Inherited requirements do not shadow runtime
dev test, lint, types No include cycle back into dev
release dev Release helper versions still current

A cycle is a structural defect: it makes the group unresolvable and the whole include graph unreliable. The matrix above is the record to keep next to the manifest, because it shows the intended graph and the risk each edge carries.

The published metadata before and after should look like this.

Metadata field Before migration After migration
Requires-Dist (core) runtime requirements unchanged
Provides-Extra existing extras unchanged
Requires-Dist (extras) conditional runtime requirements unchanged
group requirements absent absent

An empty diff in the last two rows is the pass condition from F001 applied to your package. Group data appearing in the built distribution, the backend or tool is not following the specification, and that is a compatibility finding to record rather than a reason to abandon groups.

The concrete win, loss, and implication

The concrete win is a manifest where a contributor’s first install is one command and the published contract is readable. Before the migration, a new contributor read a requirements file that might be stale and installed whatever it listed. After, the group names say what each set is for, and the core dependency list contains only what the package needs at runtime.

The concrete loss is tool support. The specification defines groups, but the installer and workflow tools your team uses each implement group handling on their own schedule. A group that works with one installer may not work with a tool in your pipeline that has not caught up. Check each tool before you depend on the group, and keep a fallback path for any tool that lags. Such verification is the price of the cleaner manifest.

The practical implication is that the split between packaging metadata and local workflow requirements is a contract boundary, and boundaries deserve explicit records. Teams that write down which requirements are public and which are private spend less time arguing about where a new dependency goes. Teams that leave it implicit re-litigate the question every time someone adds a tool.

The same boundary discipline shows up across the packaging and typing posts in this batch. Where a Python interface’s contract lives is the question the the Python Protocols vs ABCs guide covers structural versus nominal typing at an interface boundary. For dictionary-shaped API contracts, the Python TypedDict boundaries guide covers separating required from optional keys.

For the Go side of the same theme, the Go module compatibility guide covers keeping API changes inside an import contract, and the Go workspace boundaries guide covers separating local development composition from published module metadata.

Manifest classification is upstream of several risks this post deliberately does not cover. After the manifest is resolved, what happens next is covered by the Claude Code dependency install side effects guide covers network, script, and supply-chain behavior during installation. The risk of an agent proposing a nonexistent package is covered by the Claude Code hallucinated packages guide covers blocking a nonexistent dependency before it reaches the manifest.

On the trust boundary around tooling that runs during development, the Claude Code repository hooks guide covers hooks that execute in your checkout, and the Claude Code MCP trust boundaries guide covers treating tool results as untrusted input. Neither is a group-migration concern, but both sit on the same local-versus-published line.

Manifest classification also touches review and verification habits that have their own guides. After the migration, ask what Claude Code verification requires before calling the change done, and prevent false success from passing tests when the manifest check depends on a green run. A migration that reformats the file alongside the move is the pattern the Claude Code overengineering guide warns about. Keep the diff to the classification.

The verification habit connects to Claude Code cost per verified change, which treats generated output and verified work as different units. A metadata diff is a cheap check that earns its place on every packaging change. For the review side of a shared contract, Claude Code code review covers what happens when faster generation outpaces the review that has to accept it.

Evidence map showing core dependencies and extras as published metadata while dependency groups stay local and out of built distributions.
Editorial evidence map based on F001 and F002. Dependency group data stays out of built distributions; optional dependencies remain package metadata. Labels are the post author’s, not a tool output.

Checklist before you merge a group migration

Run this list against the diff before approving it. Each row is a pass condition, not a suggestion.

Check Pass condition If it fails
Classification matrix Every moved requirement has a recorded destination Complete the matrix first
Runtime imports No requirement imported by shipped code moved to a group Move it back to core or an extra
Optional features No consumer-selectable feature moved to a group Keep it in the extra
Group install Each new group installs with your tool Verify tool support or add a fallback
Workflow runs The workflow each group covers executes green Fix the group before merging
Metadata diff Built distribution metadata unchanged Investigate the backend before merging
Include graph No cycles between groups Break the cycle in the manifest
Tool compatibility Every tool that reads the manifest handles groups Record the exception and its fallback
Workflow from an existing pyproject.toml inventory through classification, group migration, build, and a metadata diff check.
Editorial workflow based on F001 and F002. The sequence describes a reviewable routine; it is not an official Python packaging command sequence.

Working with Claude Code on the migration

Give the agent three inputs: the current manifest, the classification matrix, and the destination of each requirement. Ask for the group tables as an addition and ask for a metadata diff as the verification step. The agent session works best when the check is a command that returns pass or fail, which is the shape the official best-practices guidance recommends.

Ask the agent to report three things when it finishes. The group tables it added. The requirements it moved and their destinations. The metadata diff result. A report that omits the metadata diff has not finished the migration, because the specification rule in F001 is the property that makes groups safe for local tooling.

Reviewing the agent’s classification is the reviewer’s job. The agent reads the manifest and can search imports, but the decision about whether a requirement is a consumer-facing feature is a product decision. The Claude Code verification guide covers the review questions: what changed, what proves it, and what was not checked.

Tradeoff between a cleaner manifest with grouped local tooling and the tool-support verification each group requires.
Editorial tradeoff diagram based on F001 and F002. Cleaner manifest structure is exchanged for a tool compatibility check; the published contract is unchanged when the migration is done correctly.

Data gap and future update

The specification rule behind F001 is clear, but tool support for groups is not uniform, and this post does not name a minimum version for any installer or build backend. The gap matters because a group that installs with one tool may fail with another, and the fix is per-tool verification rather than a general claim.

PEP 735 and the packaging guides were reachable at research time. Tool changelogs move faster than specification pages, so a future update should add the version at which each major installer and build backend supported groups, plus any known gaps. No such evidence was collected in the research pass behind this post.

No benchmark, install-time measurement, or security claim is made here. The migration is a manifest restructure, and its effect on install time or supply-chain risk is out of scope. A later draft needing those numbers would require require a separate measurement pass.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. It is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.

FAQ

Do dependency groups replace extras?

No. Extras are published metadata that consumers request; groups are local development requirements that never reach a built distribution. A package that has optional runtime features still needs extras for them. The specification rule behind F001 is what keeps group data out of distributions, which is exactly why groups cannot do an extra’s job.

What happens if I move a runtime requirement into a group?

Consumers who install the package stop receiving it, and the package fails at import time on their machine. Your local environment keeps working because the requirement is installed from the group. Search shipped source for each requirement that changed buckets during review. A hit means move it back to core or an extra.

Can groups include other groups?

Yes, by name. A common pattern is a dev group that includes test, lint and types so contributors have one install target. Include cycles are the hazard to check for, since a cycle makes the group unresolvable. The include graph table in the review section is the record to keep.

Does group support work the same in every tool?

The specification defines groups, and individual tools implement them. This post does not claim uniform support, and the concrete loss section treats per-tool verification as a required step. Check each installer and build backend your team uses before relying on a group.

Should I keep my requirements file after the migration?

Once every requirement in it has a destination in the manifest, the file is redundant and can go. Requirements that remain make the file drift waiting to happen. The migration is finished when the manifest is the single source of truth for what the project needs and what contributors install.

This post is one of six language and build-system guides written together. The other five in the batch cover the same local-versus-published boundary in different ecosystems: Python Protocols vs ABCs, Python TypedDict Boundaries, Python Stub Drift, Go Module Compatibility, and Go Workspace Boundaries.

The batch continues with build-system and code-generation boundary work in other ecosystems. Go Module Graph Pruning covers minimal version selection and indirect entries. Cargo Feature Unification covers optional APIs in a workspace build, and Cargo Profile Boundaries covers debug and release settings. Cargo Build Scripts covers generated-artifact contracts, and Cargo Workspace Inheritance covers centralizing workspace metadata.

The JVM and .NET posts in the batch cover version and variant selection. Gradle Constraints vs Dependencies covers fixing resolution without adding edges, and Gradle Capability Conflicts covers competing components. Gradle Variant Attributes covers matching consumers to artifacts, and Maven Optional Dependencies covers keeping transitive expectations explicit. NuGet Central Package Management covers cross-project version centralization.

For generated-code boundaries, the batch covers C# Source Generators, OpenAPI Generator Customization, and GraphQL Code Generator Client Presets. Framework maintenance is covered by Django Deprecation Runway, Rails Upgrade Sequence, and Angular Update Guide.

More from this batch

More Claude Code troubleshooting

Sources

Control checklist covering the classification matrix, runtime import search, group install, workflow run, and metadata diff for a group migration.
Editorial control checklist derived from F001 and F002. Passing the checklist shows the migration was reviewed honestly; it does not prove every downstream tool handles groups identically.
Verdict that a classified, one-group-at-a-time migration keeps the published contract unchanged while giving local tooling a named home.
Editorial verdict based on F001 and F002. A group migration that leaves the metadata diff empty has kept the consumer contract intact; tool support still needs per-tool verification.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →