Dependency Groups (PEP 735 Implementation)

1.3.1 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

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}")

view raw JSON →