Registry / devops / dependency-groups

dependency-groups

JSON →
library1.3.1pypypi✓ verified 49d ago

The `dependency-groups` library is an active implementation of PEP 735, a standard defining a mechanism for storing package requirements in `pyproject.toml` files that are not included in built project metadata. This library, currently at version 1.3.1 and maintained by the Python Packaging Authority, enables parsing and resolving these dependency groups, including handling nested group inclusions. It's primarily used for development-time dependencies like testing, linting, or documentation, distinguishing them from runtime or optional user-facing dependencies.

devopsworkflow
pip install dependency-groups
Install & Compatibility
Where this runs
tested against v1.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.960 runs
installs and imports cleanly · install 0.0s · import 0.146s · 18.7MB
glibc
py 3.103.960 runs
installs and imports cleanly · install 1.6s · import 0.131s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

resolve
from dependency_groups import resolve
A functional interface to resolve a dependency group to a list of strings.
DependencyGroupResolver
from dependency_groups import DependencyGroupResolver
An object-oriented interface for more advanced resolution and inspection.

This quickstart demonstrates how to parse `dependency-groups` from a `pyproject.toml` (simulated here as a string) and use the `resolve` function to get a flattened list of requirements for a specific group, including handling nested `include-group` directives.

import tomllib import io from dependency_groups import resolve # Simulate a pyproject.toml file content pyproject_content = """ [dependency-groups] test = ["pytest", {"include-group": "runtime"}] runtime = ["flask"] build = ["build", "twine"] """ # In a real project, you would load from 'pyproject.toml': # with open("pyproject.toml", "rb") as fp: # pyproject = tomllib.load(fp) # groups = pyproject["dependency-groups"] # For quickstart, load from the string pyproject = tomllib.load(io.BytesIO(pyproject_content.encode('utf-8'))) groups = pyproject["dependency-groups"] # Resolve the 'test' dependency group resolved_test_deps = resolve(groups, "test") print(f"Resolved 'test' group: {resolved_test_deps}") # Resolve the 'build' dependency group resolved_build_deps = resolve(groups, "build") print(f"Resolved 'build' group: {resolved_build_deps}")
dependency-groups --version
Debug
Known issues
gotchaPEP 735 (Dependency Groups) is a relatively new standard (accepted October 2024). While `dependency-groups` implements the specification, broader tooling support (e.g., `pip`, `uv`, `poetry`) is still evolving. Ensure your entire toolchain supports dependency groups as expected.
fix
Consult the documentation of your package manager (e.g., `pip`, `uv`, `poetry`, `pdm`) for their current level of PEP 735 support. Keep tools updated to their latest versions.
affects: All versions
gotchaAvoid creating dependency group names that match existing `project.optional-dependencies` names. PEP 735 advises against this, and tools may treat such name collisions as errors or lead to confusing behavior due to overlapping install UX.
fix
Use distinct names for your dependency groups (in `[dependency-groups]`) and optional dependencies (in `[project.optional-dependencies]`) within your `pyproject.toml`.
affects: All versions
gotchaDependency group includes must not contain cycles (e.g., group A includes B, and B includes A). Tools implementing PEP 735, including `dependency-groups`, are expected to detect and report errors if cycles are found during resolution.
fix
Carefully structure your `include-group` declarations in `pyproject.toml` to ensure no circular dependencies exist between your groups.
affects: All versions
gotchaDependency groups are explicitly *not* included in the project's metadata when a package is built and distributed (e.g., to PyPI). They are intended for local development workflows and not for end-user installation via standard package managers.
fix
For runtime optional features that users can install, use `project.optional-dependencies`. For core runtime dependencies, use `project.dependencies`.
affects: All versions
gotchaThe test script or environment attempts to use `tomllib`, which is a standard library module introduced in Python 3.11. Running tests on Python versions older than 3.11 (e.g., Python 3.9) will result in a `ModuleNotFoundError`.
fix
Ensure the test environment uses Python 3.11 or newer, or modify the test script to use the `tomli` backport for compatibility with older Python versions (e.g., `import tomli as tomllib` or conditionally import `tomli` if `tomllib` is unavailable).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dependency_groups'
The `dependency-groups` library has not been installed in your Python environment.
fix
Run `pip install dependency-groups` to install the library.
Error: Invalid TOML structure in pyproject.toml
The `[dependency-groups]` table or its contents are malformed, or it is incorrectly nested under a tool-specific table instead of being a top-level table.
fix
Ensure the `[dependency-groups]` table is at the top level of your `pyproject.toml` and contains valid TOML syntax for group names and dependency specifiers, e.g., `[dependency-groups]
docs = ["sphinx"]`.
DependencyGroupError: Cyclic dependency detected in group includes
You have defined a chain of `include-group` declarations in your `pyproject.toml` that forms a cycle (e.g., group A includes B, and B includes A), which is forbidden by PEP 735.
fix
Review your `[dependency-groups]` definitions in `pyproject.toml` and break any circular `include-group` references.
ResolutionImpossible: Conflicting requirements found for dependencies across groups
When resolving multiple dependency groups or a group with project dependencies, incompatible version constraints were found for the same package, making a unified resolution impossible.
fix
Adjust the version specifiers for the conflicting package(s) within your `[dependency-groups]` to ensure they are compatible, or specify the groups to be resolved separately if their dependencies are not intended to be compatible within the same environment.
Upgrade
Version history
1.3.1latest on PyPI
Audit
Dependencies
tomllibrequiredRequired for parsing pyproject.toml. Built-in Python 3.11+, explicit dependency for older Python versions (3.8-3.10) if installing `dependency-groups[cli]`.
Agent activity
96 hits · last 30 days
node
8
mj12bot
4
seranking-bot
3
ahrefsbot
2
amazonbot
2
Amazon
1
Resources