2.1 The dependencies of the server
Build it yourself. Read the tutorial 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
This part does not start where the part before it ends, because the walk skips some changes. This command puts the files that this part starts from in place of yours. Run it, and then go on:
git fetch --quiet --tags --force origin; git restore --source fc8c3bce8360 --staged -- :/ && git restore --source step-01 --staged --worktree -- :/If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:
git fetch --quiet --tags --force origin; git rm -rq --cached --ignore-unmatch -- :/ && git restore --source step-01 --staged --worktree -- :/just setupThe 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.
uv add fastapi uvicornThe command adds both packages to dependencies in pyproject.toml, and writes their versions into uv.lock.
uv run uvicorn --versionuvicorn prints its version, and the version of Python that runs it.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check 18dd9dfb1c95If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git fetch --quiet --tags --force origin; git restore --source step-01 --staged -- :/ && git restore --source 18dd9dfb1c95 --staged --worktree -- :/What changed
pyproject.toml: FastAPI and uvicorn, the dependencies of the server. 4 lines added, 1 removed. It comes fromuv add fastapi uvicorn. The file- look at
"fastapi>=0.143.2",
- look at
uv.lock: the exact versions of FastAPI, uvicorn, and the packages that they need. 263 lines added. It comes fromuv add fastapi uvicorn. The file
The diff that uv add fastapi uvicorn makes in 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 itselfThis part ends at the code at 18dd9dfb1c95, partway through step-02. The code after this part