2.1 The dependencies of the server

Read the tutorial. Build it yourself is the other way to read this part.

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at step-01. The code before this part

To look at this code on your machine, run these commands. The first one makes a clone, if this folder has none:

[ -d cheesecracker ] || git clone https://github.com/rahuldave/cheesecracker
cd cheesecracker
git fetch --quiet --tags --force origin
git switch --detach step-01
just setup

The whole tutorial then tells pytest where the tests are, adds eleven unit tests of power(), and the recipe just test. Next comes the server, which needs FastAPI to build it and uvicorn to run it. They are dependencies of the project itself, and of no group.

2.1 FastAPI, and uvicorn to serve it

FastAPI is a library for web APIs. A path is the part of an address after the name of the server, such as /health. A Python function answers the requests to one path when a line such as @app.get("/health") stands just above it. FastAPI uses the type written next to each argument, such as float, to check the values of each request. It also writes the pages of the API's docs.

uvicorn is the server. It waits for requests on a numbered port of the machine, such as 9000, and hands each request to the app.

The server needs FastAPI and uvicorn to run, so they are dependencies of the project itself, and not of a group.

This change came from running uv add fastapi uvicorn.

The command adds both packages to dependencies in pyproject.toml, and writes their versions into uv.lock.

uv run uvicorn --version

uvicorn prints its version, and the version of Python that runs it.

What changed

  • pyproject.toml: FastAPI and uvicorn, the dependencies of the server. 4 lines added, 1 removed. It comes from uv add fastapi uvicorn. The file
    • look at "fastapi>=0.143.2",
  • uv.lock: the exact versions of FastAPI, uvicorn, and the packages that they need. 263 lines added. It comes from uv add fastapi uvicorn. The file

The diff of pyproject.toml
@@ -4,7 +4,10 @@ version = "0.1.0"
 description = "The Cheese App's API server, with its tests, its checks and its Docker images"
 readme = "README.md"
 requires-python = ">=3.12"
-dependencies = []
+dependencies = [
+    "fastapi>=0.143.2",
+    "uvicorn>=0.54.0",
+]
 
 [tool.uv]
 # The project is an application, not a library: uv installs its dependencies, and not the project itself

This change on GitHub

This part ends at the code at 18dd9dfb1c95, partway through step-02. The code after this part