Dependency Groups (PEP 735 Implementation)
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.
Warnings
- gotcha PEP 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.
- gotcha Avoid 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.
- gotcha Dependency 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.
- gotcha Dependency 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.
Install
-
pip install dependency-groups -
pip install "dependency-groups[cli]"
Imports
- resolve
from dependency_groups import resolve
- DependencyGroupResolver
from dependency_groups import DependencyGroupResolver
Quickstart
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}")