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.
pip install dependency-groupsVerified import paths — ran on the pinned version, not inferred.
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.
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.
Use distinct names for your dependency groups (in `[dependency-groups]`) and optional dependencies (in `[project.optional-dependencies]`) within your `pyproject.toml`.
Carefully structure your `include-group` declarations in `pyproject.toml` to ensure no circular dependencies exist between your groups.
For runtime optional features that users can install, use `project.optional-dependencies`. For core runtime dependencies, use `project.dependencies`.
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).
Run `pip install dependency-groups` to install the library.
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"]`.
Review your `[dependency-groups]` definitions in `pyproject.toml` and break any circular `include-group` references.
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.