Development Dependencies and Optional Groups

Convert development, testing, and documentation dependencies from requirements-dev.txt to pyproject.toml optional-dependencies groups.

Advanced Features

Detailed Explanation

Many Python projects split dependencies into separate files: requirements.txt for production and requirements-dev.txt (or requirements-test.txt) for development tools. In pyproject.toml, these are organized under [project.optional-dependencies] as named groups.

requirements-dev.txt:

pytest>=7.4
pytest-cov>=4.1
pytest-asyncio>=0.23
ruff>=0.1.6
mypy>=1.7
black>=23.11
pre-commit>=3.5

Converted to pyproject.toml:

[project.optional-dependencies]
dev = [
    "pytest>=7.4",
    "pytest-cov>=4.1",
    "pytest-asyncio>=0.23",
    "ruff>=0.1.6",
    "mypy>=1.7",
    "black>=23.11",
    "pre-commit>=3.5",
]

Multiple optional groups in pyproject.toml:

[project.optional-dependencies]
test = [
    "pytest>=7.4",
    "pytest-cov>=4.1",
    "coverage[toml]>=7.3",
]
lint = [
    "ruff>=0.1.6",
    "mypy>=1.7",
]
docs = [
    "sphinx>=7.2",
    "sphinx-rtd-theme>=2.0",
    "myst-parser>=2.0",
]
dev = [
    "my-project[test,lint,docs]",
]

The dev meta-group pattern is a popular convention where the dev group references all other optional groups using self-referencing extras (my-project[test,lint,docs]). Users can install everything with pip install -e ".[dev]" or just testing tools with pip install -e ".[test]".

This approach replaces the multiple requirements-*.txt files pattern with a single pyproject.toml that clearly defines what each dependency group is for.

Use Case

Consolidating separate requirements-dev.txt, requirements-test.txt, and requirements-docs.txt files into a single pyproject.toml with organized optional-dependency groups.

Try It — Requirements ↔ Pyproject

Open full tool