Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Python builds (pip, venv, requirements.txt)
What is pyproject.toml and how is it different from requirements.txt?
IntermediateConceptPython builds (pip, venv, requirements.txt)
Answer
Short answer
pyproject.toml is the modern, standard project file for Python. It describes the project itself — name, version, Python version, dependencies, optional extras and tool config (pytest, ruff, black) — in one place. requirements.txt is just a flat list of packages to install. Tools like Poetry, uv, Hatch and plain pip all read pyproject.toml.
Example
[project]
name = "orders-api"
version = "1.3.0"
requires-python = ">=3.12"
dependencies = ["fastapi>=0.111", "uvicorn[standard]>=0.30", "sqlalchemy>=2.0"]
[project.optional-dependencies]
dev = ["pytest", "ruff"]
[tool.ruff]
line-length = 100
How installs look
pip install . # install the project and its dependencies
pip install ".[dev]" # plus dev extras
uv sync --frozen # uv: install exactly from uv.lock
poetry install --no-root # Poetry: from poetry.lock
Key point for DevOps
pyproject.toml usually lists ranges; the lockfile (poetry.lock, uv.lock) pins exact versions. In CI, always install from the lockfile with the "frozen" option.
What to say in the interview
"pyproject.toml is the standard project metadata and config file, replacing setup.py and centralising tool config. Dependencies there are often ranges, so reproducibility comes from the tool's lockfile, which CI installs in frozen mode."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Python apps: pip, venv & requirements.txt
More on Python builds (pip, venv, requirements.txt)
How do you install dependencies and run a Python application?BeginnerWhat is a Python virtual environment and why do we need it?BeginnerWhat is requirements.txt and how do you pin versions?BeginnerHow do you run a Flask application in development and in production?BeginnerWhat is gunicorn and how many workers should you run?BeginnerWhat is the difference between WSGI and ASGI?Intermediate