requirements.txt vs pyproject.toml: What’s the Difference
Why Python packaging moved from requirements.txt to pyproject.toml, what each actually does, and whether you still need a requirements.txt file
If you’ve followed an older Python tutorial, you’ve run pip install -r requirements.txt. If you’ve started a project with uv, Poetry, or Hatch recently, you have a pyproject.toml instead — and possibly no requirements.txt at all.
requirements.txt: a flat list, nothing else
A requirements.txt file is exactly what it looks like — a plain list of package names and versions, one per line:
requests==2.34.2
click>=8.5
It doesn’t distinguish between direct dependencies (what your code actually imports) and transitive ones (what those packages depend on in turn) unless you generate it carefully. It has no concept of project metadata — name, version, author, entry points — and no standard way to separate production dependencies from development-only ones like test runners, beyond maintaining a second file (requirements-dev.txt) by convention.
pyproject.toml: one file, standardized structure
pyproject.toml came in two steps. PEP 518 introduced the file in 2016 for declaring the build system, and PEP 621 standardized the [project] table for a project’s metadata and dependencies. The PyPA’s specification now lists four tables: [build-system], [project], [dependency-groups] and [tool].
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = ["requests>=2.32", "click>=8.0"]
[project.optional-dependencies]
cli = ["rich"]
[dependency-groups]
dev = ["pytest>=9.0"]One file covers the build system, project metadata, direct dependencies, extras and development groups, in a format every modern packaging tool (uv, Poetry, Hatch, pip itself) understands the same way, rather than each tool inventing its own config file.
The last two tables look alike and are not the same thing. [project.optional-dependencies] declares extras: they are published with your package, so a user can install my-project[cli]. [dependency-groups] (PEP 735, now final) declares groups that stay with the project and are not published, which is where development tools belong. They were tested with pip 26.3 and uv 0.13.8: pip install . installed requests and click from the [project] table, pip install --group dev installed pytest from the group, and uv add --dev pytest wrote a [dependency-groups] entry.
Do you still need a requirements.txt?
Not for the dependency list itself — that’s what pyproject.toml now handles. Some teams still generate a requirements.txt as a lock-file-like export for deployment environments that expect one (certain CI systems, Docker base images, or platforms that specifically look for that filename), but it’s a build artifact at that point, not the source of truth. uv can write one with uv export --format requirements-txt, which lists every resolved package with its hashes (and an -e . line for the project itself). If you’re using uv or Poetry, your real lock file is uv.lock or poetry.lock. There is also a tool-neutral lockfile format now: PEP 751’s pylock.toml, which Hatch and uv can write, which pip’s experimental pip lock command produced in a test, and which pip’s release notes show it can install from with pip install -r pylock.toml. See our packaging tools comparison for how those differ.
Starting a new project today
Use pyproject.toml — it’s the standardized, tool-agnostic format, and every current packaging tool is built around it. There’s no reason to start a new project with a bare requirements.txt in 2026; that pattern exists mainly in older codebases that haven’t migrated yet, not as an active recommendation.
Frequently Asked Questions
What’s the difference between requirements.txt and pyproject.toml?
requirements.txt is a flat list of package names and versions, nothing else, with no project metadata and no distinction between direct and transitive dependencies. pyproject.toml is a standardized single file covering the build system, project metadata, dependencies, optional extras, and development dependency groups.
Do you still need a requirements.txt file?
Not for the dependency list itself — pyproject.toml handles that now. Some teams still generate one as a deployment artifact for CI systems or Docker images that expect that filename, but it’s a build output, not the source of truth.
What should a new Python project use in 2026?
pyproject.toml — it’s the standardized, tool-agnostic format every current packaging tool (uv, Poetry, Hatch, pip) is built around. There’s no reason to start a new project with a bare requirements.txt.
What’s the actual lock file if you use uv or Poetry?
uv.lock or poetry.lock respectively. pyproject.toml declares your dependencies, but the lock file pins the exact resolved versions for reproducible installs. A tool-neutral lockfile format, pylock.toml (PEP 751), is now a final standard too; uv and Hatch can write it, and pip has an experimental pip lock command.
What is the difference between optional-dependencies and dependency-groups?
[project.optional-dependencies] declares extras, which are published with the package so users can install it as package[extra]. [dependency-groups] (PEP 735) declares groups that stay with the project and are not published, which suits dev, test and docs tools. pip install —group dev and uv add —dev both use it.
Can pip install from pyproject.toml?
Yes. pip install . installs the project and its [project] dependencies, and recent pip versions (tested with 26.3) can install a dependency group from the file with pip install —group dev. pip does not lock anything by default.