Skip to content

Courses / GenAI & LLM / Module 0

Module 0: Prerequisites: Python, Git, HTTP and Linux

10 h · theory 3 · hands-on 5 · project 0 · revision 2

You will be able to

  • Write typed, tested Python (functions, classes, async basics)
  • Use Git branches and pull requests
  • Call a REST API and read JSON
  • Work in a Linux shell

Capstone increment: Create the capstone repo with README, .gitignore, pre-commit and a hello-world FastAPI endpoint.

Job-description skills: Python, Git, REST APIs · Lab tools: python3.12, git, curl

1. Why these four skills, and how much is enough

This module is optional. If you already write typed, tested Python, use Git branches and pull requests, call REST APIs comfortably and work in a Linux shell, take the diagnostic quiz at the end and skip ahead.

Every later module assumes these four skills because GenAI engineering is mostly ordinary software engineering wrapped around an unreliable component. The model call is one line; the retries, validation, tests, deployment and logs around it are the job. Employers screen for exactly this: in the job descriptions we analysed, Python, APIs and Git appear in nearly every listing, far more often than any specific model or framework.

The bar is practical, not academic: you should be able to read an unfamiliar Python file, write a function with a test, open a pull request, and debug a failing HTTP call from its status code and body.

Branchgit switch -c feat/xCode + testtyped Python, pytestCommitpre-commit hooksPull requestdescribe the whyCIlint, test, buildMergemain stays greenEvery change in this course follows the same loopred build: fix on the branch
Small branches, tests before merge, CI as the gate. The capstone repo uses this loop from day one.

2. Typed, tested Python

Use type hints everywhere (str, list[LineItem], float | None). They cost little, they let your editor and mypy catch mistakes, and Pydantic (Module 4) turns them into runtime validation of model output. Dataclasses give you clean value objects without boilerplate.

Write tests with pytest from the first day of the capstone. A test is a function whose name starts with test_ and that uses plain assert. Test the boring parts hardest: parsing, money, dates and anything you will later ask a model to produce, because you need a ground truth to compare model output against.

Know async basics: async def, await, and why an API server handling many slow LLM calls uses asyncio instead of threads. You won't write event loops by hand, but FastAPI endpoints and streaming responses are async.

Common misconception: “It’s a prototype, tests can come later.” In LLM work the tests are how you find out whether a prompt change helped. Without them every change is a guess.

3. Git and pull requests

Work on short-lived branches, commit small logical steps with messages that say why, and merge through a pull request even when you work alone. CI runs your tests on every pull request (Module 14 adds evals to that gate).

Commands to have in your fingers: git switch -c, git add -p, git commit, git push -u, git pull --rebase, git log --oneline, git diff, and git restore. Learn to read a merge conflict and resolve it by hand.

Never commit secrets. Keep API keys in a .env file listed in .gitignore and commit a .env.example with empty values instead. A pre-commit hook (the pre-commit framework) can block keys and run formatters before every commit.

In production: Leaked API keys are found by bots within minutes of a public push. If one leaks, rotate it at the provider first, then clean the history.

4. HTTP and JSON: reading what the server tells you

Every model API is HTTP plus JSON. A request has a method (POST), headers (Authorization, Content-Type) and a JSON body; a response has a status code, headers and a body. Read all three when something fails.

Status codes decide what you do next: 2xx succeeded; 400 and 422 mean your request is wrong, so retrying won't help; 401 and 403 are keys and permissions; 429 means you're rate limited and should wait (respect the Retry-After header); 5xx means the server had trouble and a retry with backoff is reasonable.

Always set a timeout on outbound calls. A request without a timeout can hang a worker forever, and LLM calls are slow enough that defaults matter.

5. The Linux shell you actually need

Your capstone runs in Linux containers, so you need: navigating (cd, ls, find), reading files (cat, less, tail -f for logs), environment variables (export, env), processes (ps, kill, top), pipes and grep, file permissions (chmod), and curl to call APIs by hand.

On Windows, install WSL 2 with Ubuntu and work there; it avoids a whole class of path and line-ending problems later. Practise by calling a public JSON API with curl and piping the result through python -m json.tool.

Tip: Spend one evening on the Missing Semester shell lecture. It repays itself every week of this course.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

Lab 0.1: Create the capstone repository

Create a GitHub repository from the course starter, clone it into WSL or Linux, create a virtual environment, install requirements, and run pytest. Add a pre-commit config with ruff and a secret scanner.

Expected: pytest shows the starter tests passing; a commit containing a fake key like sk-test-123 is blocked by the hook.

Lab 0.2: Your first pull request

On a branch, add a GET /version endpoint to the FastAPI app that returns the git commit hash from an environment variable, with a test. Open a pull request and merge it after CI passes.

Expected: A merged pull request with a green CI run, and curl localhost:8000/version returns JSON.

Lab 0.3: Debug a failing API call

Use curl with -i to call a public API with a missing parameter, a wrong key and a valid request. For each, write down the status code, the key header and what you would change.

Expected: A three-row table: status, cause, fix. You can explain why 400 isn't retried but 429 is.

Go deeper

Videos

Further reading

  • Docs The Python Tutorial · Python docs. The official tour; read chapters 4–9 if any of functions, classes or modules feel shaky.
  • Book Pro Git · Scott Chacon and Ben Straub. Chapters 2 and 3 cover everything this course needs: commits, branches and merging.
  • Docs An overview of HTTP · MDN Web Docs. Requests, responses, status codes and headers: what every LLM API call is made of.
  • Course The Missing Semester of Your CS Education · MIT. Short lectures on the shell, scripting, editors and version control.

GitHub repositories

Checkpoint quiz

1. An API returns 422 Unprocessable Entity. What should your client do?
2. Where should an API key live in the capstone?
3. Why does the capstone API use async endpoints?
4. What does a pull request add over pushing straight to main?
5. Which status code tells you to slow down and retry later?

Interview questions

  1. How do you keep secrets out of a Git repository, and what do you do if one leaks?
  2. Which HTTP errors would you retry automatically, and which wouldn’t you? Why?
  3. Why would you choose async endpoints for a service that calls an LLM?
  4. Walk me through how you’d debug an API call that works in curl but fails from your Python code.
  5. What do you test first in a new service, and why?

Ask the professor

Sign in to ask questions about this module.

Discussion

Community discussion appears here once giscus is configured (see README).