liveBook · Manning

Requirements.txt

As explained in Road to Kubernetes

A requirements file is a text configuration file that lists Python packages and optionally their required versions for installation.

A requirements.txt file is a plain-text dependency list for a Python project. It lets pip install the project’s third-party packages together instead of installing them one at a time. section 2.1.1

Use the file to make Python environments repeatable:

  • Create requirements.txt in the project source folder. section 2.1.1
  • List one third-party package per line, optionally declaring specific versions. section 2.1.1
  • With the virtual environment activated, run python -m pip install -r src/requirements.txt to restore the dependencies. section 2.1.1
  • Keep the virtual environment out of Git; requirements.txt records what can recreate it. section 2.3.2

FastAPI dependency list

fastapi jinja2 uvicorn gunicorn Install the complete list with: python -m pip install -r src/requirements.txt section 2.1.1

Listing 2.5 FastAPI requirements.txt
fastapi
jinja2
uvicorn
gunicorn

Shows a minimal requirements.txt for the Python web application. section 2.1.1

How Road to Kubernetes covers it

How deep it goes
Defines package lists, demonstrates bulk installation, and notes versions, ranges, and Git repositories without detailing complex formats.
Examples
Uses FastAPI, Jinja2, Uvicorn, and Gunicorn in a requirements.txt file.
What it assumes
Assumes a Python project and virtual environment, while teaching dependency installation from a file.
What you can do after
Apply it via pip to restore a Python environment from a dependency list.
How it connects
Connects Python packages, pip, virtual environments, Git, and .gitignore.

Also explained in

Compare how 4 books explain requirements.txt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.