Notes

Switching From Python requirements.txt to pyproject.toml

December 6, 2025

In python, a lot of projects are switching over from the old requirements.txt format of declaring dependencies to pyproject.toml and others. pyproject.toml can condense multiple requirements-*.txt files as well as other package metadata into a single file, simplifying several package maintenance processes.

The steps to switch are:

  1. Create a bare bones pyproject.toml file in the root of your package:

    [project]
    name = "<NAME>"
    version = "<VERSION>"
    dependencies = [
        "dependency1",
        "dependency2",
    ]
    

    Copy a name and version from your setup.py if you’re still using that. Copy dependencies from your requirements.txt. Dependencies in pyproject.toml follow the same format as requirements.txt and support dependency versioning with ==, >=, and < limits.

  2. If you’ve split your requirements-test.txt or other types of dependencies, you can include them in your pyproject.toml as optional dependencies:

    [project]
    ...
    
    [project.optional-dependencies]
    test = [
        "dependency3",
        "dependency4",
    ]
    
  3. Delete your requirements.txt. Hopefully you’re using version control.

  4. Switch your build commands from pip install -r requirements.txt to pip install -e .. If you want to install optional test dependencies too, you can do that with pip install -e .[test].