Basic requirements.txt to pyproject.toml

Learn how to convert a simple requirements.txt file with basic package names and version pins to the pyproject.toml dependencies format defined by PEP 621.

Getting Started

Detailed Explanation

Converting a basic requirements.txt to pyproject.toml is the most common migration task for Python projects adopting modern packaging standards. A simple requirements.txt lists one package per line, optionally with a version specifier.

Example requirements.txt:

requests==2.31.0
flask>=3.0
pydantic

Converted to pyproject.toml:

[project]
name = ""
version = "0.1.0"
requires-python = ">=3.8"

dependencies = [
    "requests==2.31.0",
    "flask>=3.0",
    "pydantic",
]

Key differences in the format:

  1. String quoting. Each dependency in pyproject.toml must be enclosed in double quotes and placed inside a TOML array.
  2. Trailing commas. TOML allows trailing commas in arrays, making it easy to add or remove entries.
  3. Project metadata. pyproject.toml requires additional fields like name, version, and requires-python that don't exist in requirements.txt.
  4. Section headers. Dependencies live under the [project] table in pyproject.toml, not as a flat list.

The PEP 621 format is now supported by all major Python build tools including pip, setuptools, hatch, flit, pdm, and poetry (with adapter). This makes migration straightforward and future-proof.

Use Case

Migrating a small Python script or library from the traditional requirements.txt format to pyproject.toml when adopting modern packaging with pip, hatch, or flit.

Try It — Requirements ↔ Pyproject

Open full tool