|
| 1 | +# Supported dependency managers |
| 2 | + |
| 3 | +While most dependency managers support the |
| 4 | +standard [PEP 621 format](https://packaging.python.org/en/latest/specifications/pyproject-toml/) for defining |
| 5 | +dependencies in `pyproject.toml`, not all of them do. Even those that do often provide additional ways to define |
| 6 | +dependencies that are not standardized. |
| 7 | + |
| 8 | +_deptry_ can extract dependencies from most of the package managers that support PEP |
| 9 | +621 (e.g. [uv](https://docs.astral.sh/uv/), [PDM](https://pdm-project.org/en/latest/)), including tool-specific |
| 10 | +extensions, but also from package managers that do not (or used to not) support PEP |
| 11 | +621 (e.g. [Poetry](https://python-poetry.org/), [pip](https://pip.pypa.io/en/stable/reference/requirements-file-format/)). |
| 12 | + |
| 13 | +## PEP 621 |
| 14 | + |
| 15 | +_deptry_ fully supports [PEP 621 standard](https://packaging.python.org/en/latest/specifications/pyproject-toml/), and |
| 16 | +use the presence of a `[project]` section in `pyproject.toml` to determine that the project uses PEP 621. |
| 17 | + |
| 18 | +By default, _deptry_ extracts, from `pyproject.toml`: |
| 19 | + |
| 20 | +- regular dependencies from: |
| 21 | + - `dependencies` entry under `[project]` section |
| 22 | + - groups under `[project.optional-dependencies]` section |
| 23 | +- development dependencies from groups under `[dependency-groups]` section |
| 24 | + |
| 25 | +For instance, with this `pyproject.toml`: |
| 26 | + |
| 27 | +```toml title="pyproject.toml" |
| 28 | +[project] |
| 29 | +name = "foo" |
| 30 | +dependencies = ["orjson>=3.0.0"] |
| 31 | + |
| 32 | +[project.optional-dependencies] |
| 33 | +cli = ["click>=8.0.0"] |
| 34 | +http = [ |
| 35 | + "httpx>=0.27.0", |
| 36 | + "uvicorn>=0.32.0", |
| 37 | +] |
| 38 | + |
| 39 | +[dependency-groups] |
| 40 | +docs = ["mkdocs==1.6.1"] |
| 41 | +test = [ |
| 42 | + "pytest==8.3.3", |
| 43 | + "pytest-cov==5.0.0", |
| 44 | +] |
| 45 | +``` |
| 46 | + |
| 47 | +the following dependencies will be extracted: |
| 48 | + |
| 49 | +- regular dependencies: `orjson`, `click`, `httpx`, `uvicorn` |
| 50 | +- development dependencies: `mkdocs`, `pytest`, `pytest-cov` |
| 51 | + |
| 52 | +!!! note |
| 53 | + |
| 54 | + Groups under `[project.optional-dependencies]` can be flagged as development dependency groups by |
| 55 | + using [`--pep621-dev-dependency-groups`](usage.md#pep-621-dev-dependency-groups) argument (or its |
| 56 | + `pep_621_dev_dependency_groups` equivalent in `pyproject.toml`). |
| 57 | + |
| 58 | +### uv |
| 59 | + |
| 60 | +Additionally to PEP 621 dependencies, _deptry_ will |
| 61 | +extract [uv development dependencies](https://docs.astral.sh/uv/concepts/dependencies/#development-dependencies) from |
| 62 | +`dev-dependencies` entry under `[tool.uv]` section, for instance: |
| 63 | + |
| 64 | +```toml title="pyproject.toml" |
| 65 | +[tool.uv] |
| 66 | +dev-dependencies = [ |
| 67 | + "mkdocs==1.6.1", |
| 68 | + "pytest==8.3.3", |
| 69 | + "pytest-cov==5.0.0", |
| 70 | +] |
| 71 | +``` |
| 72 | + |
| 73 | +### PDM |
| 74 | + |
| 75 | +Additionally to PEP 621 dependencies, _deptry_ will |
| 76 | +extract [PDM development dependencies](https://pdm-project.org/en/latest/usage/dependency/#add-development-only-dependencies) |
| 77 | +from `[tool.pdm.dev-dependencies]` section, for instance: |
| 78 | + |
| 79 | +```toml title="pyproject.toml" |
| 80 | +[tool.pdm.dev-dependencies] |
| 81 | +docs = ["mkdocs==1.6.1"] |
| 82 | +test = [ |
| 83 | + "pytest==8.3.3", |
| 84 | + "pytest-cov==5.0.0", |
| 85 | +] |
| 86 | +``` |
| 87 | + |
| 88 | +### Setuptools |
| 89 | + |
| 90 | +When using setuptools as a build backend, both `dependencies` and `optional-dependencies` can |
| 91 | +be [dynamically read](https://setuptools.pypa.io/en/stable/userguide/pyproject_config.html#dynamic-metadata) from |
| 92 | +`requirements.txt`-format files, for instance: |
| 93 | + |
| 94 | +```toml title="pyproject.toml" |
| 95 | +[build-backend] |
| 96 | +requires = ["setuptools"] |
| 97 | +build-backend = "setuptools.build_meta" |
| 98 | + |
| 99 | +[project] |
| 100 | +name = "foo" |
| 101 | +dynamic = ["dependencies", "optional-dependencies"] |
| 102 | + |
| 103 | +[tool.setuptools.dynamic] |
| 104 | +dependencies = { file = ["requirements.txt"] } |
| 105 | + |
| 106 | +[tool.setuptools.dynamic.optional-dependencies] |
| 107 | +cli = { file = ["cli-requirements.txt"] } |
| 108 | +``` |
| 109 | + |
| 110 | +In this example, regular dependencies will be extracted from both `requirements.txt` and `cli-requirements.txt` files. |
| 111 | + |
| 112 | +!!! note |
| 113 | + |
| 114 | + Groups under `[tool.setuptools.dynamic.optional-dependencies]` can be flagged as development dependency groups by |
| 115 | + using [`--pep621-dev-dependency-groups`](usage.md#pep-621-dev-dependency-groups) argument (or its |
| 116 | + `pep_621_dev_dependency_groups` equivalent in `pyproject.toml`). |
| 117 | + |
| 118 | +## Poetry |
| 119 | + |
| 120 | +_deptry_ supports |
| 121 | +extracting [dependencies defined using Poetry](https://python-poetry.org/docs/pyproject/#dependencies-and-dependency-groups), |
| 122 | +and uses the presence of a `[tool.poetry.dependencies]` section in `pyproject.toml` to determine that the project uses |
| 123 | +Poetry. |
| 124 | + |
| 125 | +In a `pyproject.toml` file where Poetry is used, _deptry_ will extract: |
| 126 | + |
| 127 | +- regular dependencies from entries under `[tool.poetry.dependencies]` section |
| 128 | +- development dependencies from entries under each `[tool.poetry.group.<group>.dependencies]` section (or the |
| 129 | + legacy `[tool.poetry.dev-dependencies]` section) |
| 130 | + |
| 131 | +For instance, given the following `pyproject.toml` file: |
| 132 | + |
| 133 | +```toml title="pyproject.toml" |
| 134 | +[tool.poetry.dependencies] |
| 135 | +python = "^3.10" |
| 136 | +orjson = "^3.0.0" |
| 137 | +click = { version = "^8.0.0", optional = true } |
| 138 | + |
| 139 | +[tool.poetry.extras] |
| 140 | +cli = ["click"] |
| 141 | + |
| 142 | +[tool.poetry.group.docs.dependencies] |
| 143 | +mkdocs = "1.6.1" |
| 144 | + |
| 145 | +[tool.poetry.group.test.dependencies] |
| 146 | +pytest = "8.3.3" |
| 147 | +pytest-cov = "5.0.0" |
| 148 | +``` |
| 149 | + |
| 150 | +the following dependencies will be extracted: |
| 151 | + |
| 152 | +- regular dependencies: `orjson`, `click` |
| 153 | +- development dependencies: `mkdocs`, `pytest`, `pytest-cov` |
| 154 | + |
| 155 | +## `requirements.txt` (pip, pip-tools) |
| 156 | + |
| 157 | +_deptry_ supports extracting [dependencies using |
| 158 | +`requirements.txt` format](https://pip.pypa.io/en/stable/reference/requirements-file-format/), which is mostly used |
| 159 | +by [pip](https://pip.pypa.io/en/stable/) and [pip-tools](https://pip-tools.readthedocs.io/en/stable/). |
| 160 | + |
| 161 | +By default, _deptry_ will look for: |
| 162 | + |
| 163 | +- regular dependencies in `requirements.txt` (or `requirements.in` if existing, assuming pip-tools is used) |
| 164 | +- development dependencies in `dev-requirements.txt` and `requirements-dev.txt` |
| 165 | + |
| 166 | +For instance, given the following `requirements.txt` file: |
| 167 | + |
| 168 | +```python title="requirements.txt" |
| 169 | +click>=8.0.0 |
| 170 | +orjson>=3.0.0 |
| 171 | +``` |
| 172 | + |
| 173 | +and the following `dev-requirements.txt` file: |
| 174 | + |
| 175 | +```python title="dev-requirements.txt" |
| 176 | +mkdocs==1.6.1 |
| 177 | +pytest==8.3.3 |
| 178 | +pytest-cov==5.0.0 |
| 179 | +``` |
| 180 | + |
| 181 | +the following dependencies will be extracted: |
| 182 | + |
| 183 | +- regular dependencies: `click`, `orjson` |
| 184 | +- development dependencies: `mkdocs`, `pytest`, `pytest-cov` |
| 185 | + |
| 186 | +!!! note |
| 187 | + |
| 188 | + If using different files for regular dependencies, [`--requirements-files`](usage.md#requirements-files) (or its |
| 189 | + `requirements_files` equivalent in `pyproject.toml`) can be used to instruct _deptry_ about the requirements files |
| 190 | + locations. Similarly, [`--requirements-files-dev`](usage.md#requirements-files-dev) (or its `requirements_files_dev` |
| 191 | + equivalent in `pyproject.toml`) can be used for requirements files containing development dependencies. |
0 commit comments