Module 00: Projects

Foundations6 projects0 of 6 complete

Starter projects are guided step by step and suit freshers. Stretch projects are open-ended, add production concerns, and suit experienced readers.

Six projects: three starters and three stretches (the open-source contribution is optional and needs a free GitHub account). Every project runs with no API key and no paid service — the only accounts anywhere are a free GitHub account for the optional parts marked below. Everything lives in or beside the ai-path workspace from lesson 00.1: ~/code/ai-path/ on macOS/Linux/WSL ($HOME\code\ai-path on native Windows PowerShell — though the path recommends WSL 2 there). Commands are shown in bash/zsh form; PowerShell alternatives appear where they differ.

The projects deliberately reuse each other: Starter A makes ai-path a real repository, Starter B drops tickets.db and a report into it, Starter C adds a scripts/ folder of shell tools, and the stretches extend the same folder. Do them in order and each one gets easier.

First time here? Do lesson 00.1 first — machine, editor, git, uv, Python 3.11+ and ~/code/ai-path itself — then read the lessons each project names. Python work uses python3 from the standard library only; there is nothing to pip install in this module.

Each project carries a time estimate for a fresher typing the code themselves; experienced developers will be faster. The estimates assume the lessons each project names are already done — reading them is extra.


Starter

Starter: The ai-path workspace, end to end#

Goal: Turn ~/code/ai-path into a proper git repository — scaffolded, committed, branched, merged through a pull request, and pushed to a remote — with a verification script that proves the repo state, exactly the way a real project starts.

Time: ~4–6 hours.

What you'll practise:

Setup: git and Python 3.11+ from 00.1. The GitHub route (steps 5–6 online) needs a free account at github.com and the GitHub CLI (brew install gh / winget install --id GitHub.cli / the apt or dnf commands in 00.4's Setup). The offline route needs nothing but git — a bare repository stands in for GitHub, exactly as in 00.4 §3.2.

Steps:

  1. Verify the machine. Save check_setup.py from 00.1 §7.2 into ~/code/ai-path/ and run python3 check_setup.py. Fix every FAIL before continuing — the troubleshooting table maps each one to a cause.
  2. Scaffold the repo. In ~/code/ai-path, create README.md (a title, one paragraph on what the folder is for, and a "Status" section), .gitignore (copy the Python block from 00.3 §4.1 plus .env, .venv/, __pycache__/), notes/ with api-facts.md, and check_setup.py from step 1. Then git init -b main, set your identity with git config user.name/user.email (00.3 §2.2) and make the first commit: git add README.md .gitignore notes/api-facts.md check_setup.py && git commit -m "chore: scaffold ai-path workspace".
  3. Make the history real. Make at least nine more atomic commits — one logical change each, imperative mood, Conventional Commits style (00.3 §3.6). Good candidates that the later projects fill in: a .gitattributes file (00.3 §4.3), notes/setup-notes.md recording your OS route and editor choice, a notes/tickets-schema.md sketching the tables Starter B will create, and — if you've done Starter C — the scripts/ folder, one commit per script. Ten commits total is the floor; more is better if the changes are real.
  4. Branch and conflict. git switch -c docs/api-notes, edit the same line of notes/api-facts.md on the branch (e.g. change a verified fact's wording), commit, git switch main, edit that same line differently on main, commit, then git merge docs/api-notes. Read the <<<<<<</=======/>>>>>>> markers, resolve to the correct merged fact, git add and git commit (00.3 §5.3). First rehearse the abort path once: redo a throwaway conflict and git merge --abort to see the file return clean.
  5. Push it — pick your remote.
    • GitHub (free account): gh auth login, then gh repo create ai-path --private --source . --remote origin --push (00.4 §3.7). Or create the repo on the website and git remote add origin <url> then git push -u origin main.
    • Offline: in a scratch folder run the bare-remote flow from 00.4 §3.2 — git init --bare origin.git, add it as origin, git push -u origin main. The lesson's bare_remote_demo.sh (Exercise 1 solution) automates the whole teammate simulation.
  6. Open and merge a pull request. Push a second branch (git switch -c docs/readme-polish, commit a README improvement, git push -u origin docs/readme-polish). Online: gh pr create --fill, read your own PR as a reviewer (00.4 §4.3–4.4), then gh pr merge --squash --delete-branch. Offline: simulate the merge with git switch main && git merge --no-ff docs/readme-polish -m "Merge branch 'docs/readme-polish'", push, delete the branch (00.4 Exercise 2).
  7. Verify it. Write verify_repo.py in the repo root — stdlib only, subprocess calls to git — checking: .git exists; git rev-list --count HEAD ≥ 10; main contains the merged feature branches (git branch --merged main); a remote named origin exists (git remote); git ls-files does not list .env; README.md, notes/api-facts.md and verify_repo.py itself are tracked. Print one PASS/FAIL line per check and exit 1 on any FAIL — the same contract as check_setup.py.

Verify it, and what you should see:

bash
python3 verify_repo.py
Example output · illustrative6 lines
[PASS] .git repository present
[PASS] 12 commits on HEAD (need >= 10)
[PASS] docs/api-notes merged into main
[PASS] remote 'origin' configured
[PASS] no secrets tracked (.env absent from git ls-files)
[PASS] README.md, notes/api-facts.md, verify_repo.py tracked

(Counts and branch names are yours; the shape is the contract. Commit counts, remote URLs and branch lists differ per machine, so treat this as illustrative.) Then prove the conflict lesson stuck: git log --oneline --graph --all should show the merge commit joining your branch, and git status should be clean.

Done when:

  • verify_repo.py prints PASS for every check and exits 0.
  • git log shows at least ten meaningful commits across main and your feature branches — not ten edits to one file.
  • You resolved a real merge conflict by hand and can explain what the markers meant.
  • The repo exists on a remote (GitHub or your bare origin.git) and git status -sb shows main...origin/main with nothing ahead or behind.
  • A pull request (real or simulated) was merged and its branch deleted.
  • notes/api-facts.md contains at least three verified API facts, each with a source and a date — the habit 00.8 §5.4 formalises.

Stretch ideas: Tag the merge v0.1.0 (annotated) and write release notes from the commit log with the whats_changed.py approach in 00.4 Exercise 15. Add CONTRIBUTING.md, CODE_OF_CONDUCT.md and .github/pull_request_template.md per 00.4 §6.1. Rehearse leak response safely: commit a .env containing only an obvious placeholder, run the local secret_scan_local.py from 00.4 §8.6, then fix the repo so a second scan is clean. Needs a free GitHub account: write the profile README and pick your pinned repos per 00.4 §9 — Module 14B builds on this.

Common problems:

  • git commit fails with "Please tell me who you are" → set user.name/user.email per 00.3 §2.2; do it repo-locally, not --global, if practising in scratch repos.
  • git push asks for a password or fails after enabling 2FA → HTTPS git auth needs a token or gh auth login, not your password (00.4 §3.5).
  • Merge conflict markers left in a file → git status keeps showing "both modified"; finish by git add + git commit, or back out entirely with git merge --abort.
  • verify_repo.py fails on the secrets check → .env got committed before .gitignore existed; untrack it with git rm --cached .env, commit, and remember the file still lives in history (00.3 §4.2).
  • Commits all say "update" or "fix" → rewrite the habit, not the history: 00.3 §3.6 is the standard your future self (and reviewers) will thank you for.

Starter

Starter: tickets.db — build it, query it, report on it#

Goal: Build the support-ticket database from the lesson's script, answer fifteen questions in SQL that between them use the whole lesson, prove an index changes a query plan, and finish with a Python report that queries the database the safe way.

Time: ~4–6 hours — the fifteen hand-written queries are the bulk of it.

What you'll practise:

  • The relational model, CREATE TABLE and every constraint, and executemany seed data (lesson 00.7, 1.2, 2.2–2.3, 2.5)
  • SELECT, WHERE, NULL's three-valued logic, ORDER BY/LIMIT (00.7, Part 3)
  • Aggregation, GROUP BY, HAVING, expressions and CASE (00.7, Part 5)
  • Subqueries, CTEs and window functions (00.7, 5.4–5.6)
  • Every JOIN shape, many-to-many and self-joins, anti-joins (00.7, Part 6)
  • Indexes and EXPLAIN QUERY PLAN (00.7, 7.3)
  • JSON functions and FTS5 inside SQL (00.7, 9.1–9.2)
  • Safe Python access: row_factory, parameterised queries, executemany, with con: (00.7, Part 8)

Setup: Python 3.11+ only — sqlite3 ships in the standard library, so there is nothing to install and no server to run. Work inside ~/code/ai-path/ (Starter A's repo, or create the folder per 00.1 §3.1 if you're doing this standalone).

Steps:

  1. Build the database. Save the complete make_tickets_db.py script from 00.7 §2.3 into ~/code/ai-path/ and run python3 make_tickets_db.py. It prints the row counts it wrote and is safe to re-run — it rebuilds tickets.db from scratch. Sanity-check with python3 -c "import sqlite3; print(sqlite3.sqlite_version)", and compare the row counts it printed with the lesson's listing under the script (customers 10, agents 4, tickets 20, tags 6, ticket_tags 24, messages 40, ticket_events 12).

  2. Answer the fifteen questions. Create questions.sql — one comment line per question, the query beneath it — and run each against tickets.db (the sqlite3 CLI if you have it, or a tiny Python runner; 00.7 §2.4 shows the shell). Type every query yourself before checking the lesson exercises and drills it resembles — the goal is fluent composition, not recognition (00.7 Exercises, drills).

    # Question Lessons it exercises
    1 Subject and status of ticket 7. §3.1
    2 Every open ticket with priority high or urgent, with the customer's name; urgent first. §3.2, §3.4, JOIN
    3 How many tickets each agent holds — including agents with none and unassigned tickets. §5.1, LEFT JOIN, COALESCE
    4 Average rating of resolved tickets, grouped by the customer's plan. §5.1–5.3, AVG, ROUND
    5 How many open tickets have no rating — and why doesn't WHERE rating > 3 find them? §3.3 NULL logic
    6 Ticket counts per channel. §5.1 GROUP BY
    7 Which tickets carry both the bug and outage tags? §6.3, EXISTS/self-join on ticket_tags
    8 Every agent's name and their manager's name (Lena has none). §6.3 self-join, LEFT JOIN
    9 ticket_events counts by kind. §5.1
    10 For status_change events, group by the JSON payload's to value. §9.1 json_extract
    11 The three customers with the most tickets, using a CTE and ROW_NUMBER. §5.5–5.6
    12 Tickets with the longest message threads (top 3). §5.4 subquery, JOIN
    13 high/urgent tickets grouped by status. §5.1–5.2 HAVING vs WHERE
    14 Agents' messages vs customers' messages — totals by author. §5.1
    15 Every open or pending ticket: id, customer, agent (or "(unassigned)"), priority, subject — urgent first, then high. everything above combined
  3. Add an index and watch the plan change. Pick the query from question 2 (it filters on status and priority). Run EXPLAIN QUERY PLAN on it before creating an index — expect a full SCAN of the tickets table (SCAN t if you aliased it as t) — then CREATE INDEX idx_tickets_status ON tickets (status) (or idx_tickets_priority), re-run the plan, and compare (00.7 §7.3). Write the before/after pair into notes/tickets-db.md with one sentence on the trade-off (faster reads, slower writes). Drop the index when done if you like — or keep it and note that in your commit.

  4. Write the report. Create report.py — the open/pending digest — using the §8.1 pattern: sqlite3.connect, con.row_factory = sqlite3.Row, a parameterised WHERE t.status IN (?, ?) (never f-string SQL, §8.2), COALESCE for the unassigned agent, and ORDER BY matching question 15. Accept the statuses as sys.argv so python3 report.py open pending works.

  5. Prove the safe/unsafe difference. In a scratch copy (or on scratch.db — §8.2's warning applies: don't mutate the demo data you want to keep), run the lesson's injection demo: lookup("7 OR 1=1") unsafe returns all rows; the parameterised version returns []. Paste both results into notes/tickets-db.md.

  6. Commit it. If Starter A is done, commit make_tickets_db.py, questions.sql, report.py, notes/tickets-db.md (and tickets.db only if you decide binary data belongs in git — 00.3 §4.5 explains why it usually doesn't; .gitignore it and keep the script as the source of truth).

Verify it, and what you should see:

bash
python3 make_tickets_db.py && python3 report.py open pending

The script's own output ends with Wrote tickets.db. The report prints one row per open/pending ticket — the lesson's verified run on the seed data (Python 3.14, SQLite bundled):

Example output · illustrative10 lines
id=2   customer='Alan Turing'       agent='Priya Nair'     priority='urgent' subject='Export to CSV times out on large reports'
id=15  customer='Dennis Ritchie'    agent='Lena Fischer'   priority='urgent' subject='SSO login broken after IdP certificate rotat.'
id=12  customer='Grace Hopper'      agent='Priya Nair'     priority='normal' subject='Search returns stale results after edit'
id=18  customer='Frances Allen'     agent='Lena Fischer'   priority='normal' subject="Cannot delete workspace — 'in use' error"
id=5   customer='Margaret Hamilton' agent='(unassigned)'   priority='low'    subject='How do I add a second admin user?'
id=8   customer='Barbara Liskov'    agent='Lena Fischer'   priority='low'    subject='Request: dark mode for the admin panel'
id=4   customer='Katherine Johnson' agent='Tom Becker'     priority='high'   subject='Webhook deliveries failing with 500'
id=11  customer='Ada Lovelace'      agent='Tom Becker'     priority='high'   subject='Two-factor codes not arriving by SMS'
id=13  customer='Katherine Johnson' agent='(unassigned)'   priority='high'   subject="Bulk import fails with 'row 47: bad date'"
id=17  customer='Ken Thompson'      agent='Tom Becker'     priority='high'   subject='Webhook signature validation failing'

(The exact dict formatting depends on how you print rows; the set and order of rows is fixed by the ORDER BY. Note priority DESC sorts alphabetically — urgent, normal, low, high — which is why high lands last; a CASE rank would fix that, per lesson exercise 1's note.) Spot-checks with verified answers: question 3 gives Priya Nair 7, Tom Becker 4, Sam Rivera 4, Lena Fischer 3, (unassigned) 2; question 5's answer is 7; question 7 returns tickets 2 and 6; the index plan flips from a SCAN of tickets to SEARCH … USING INDEX idx_tickets_status (status=?)-style output.

Done when:

  • tickets.db builds from the script and all fifteen questions return sensible, verified answers — several match the lesson's own exercise/drill outputs exactly.
  • Your questions.sql uses at least one JOIN of each kind the lesson covers (inner, left, self) plus GROUP BY/HAVING, a CTE or window function, a subquery, json_extract, and EXISTS or an anti-join.
  • The before/after EXPLAIN QUERY PLAN pair is recorded in notes/tickets-db.md with the trade-off sentence.
  • report.py runs parameterised queries only, accepts statuses as arguments, and its output matches the digest above.
  • The injection demo is reproduced once, safely, and explained in your notes.

Stretch ideas: Add an FTS5 virtual table over ticket subjects and compare MATCH vs LIKE results (00.7 §9.2). Write the same digest as a single CTE chain instead of one big join (§5.5). Add a VACUUM INTO 'backup.db' backup step and a tiny migration note for the next schema change (§7.5). Going further: this is the shape of the cost/usage tables in 11A.2 and the eval-results tables in 10A.2 — same GROUP BY/SUM muscles.

Common problems:

  • no such table → you ran the queries in the wrong folder; tickets.db is a file — check pwd and that make_tickets_db.py printed Wrote tickets.db (00.2 §1.7).
  • Counts that don't match the lesson → the database was mutated by a demo (UPDATE/DELETE/executemany exercises); re-run python3 make_tickets_db.py — it rebuilds cleanly by design.
  • PRAGMA foreign_keys = ON "not working" → you set it after other statements inside an open transaction; set pragmas immediately after connect() (§8.3).
  • report.py returns everything or errors on quotes → you interpolated the status into the SQL string; use ? placeholders (§8.2).
  • The index "did nothing" → SQLite correctly chose SCAN anyway on a 20-row table — indexes pay off on larger tables; check the plan text and try WHERE customer_id = 3 like the lesson does.

Starter

Starter: Shell toolkit — five scripts that earn their keep#

Goal: Write five small, safe, documented shell scripts — a log summariser, a bulk renamer, a backup script, a JSON report and a project scaffolder — that you will actually reuse, with a README explaining each.

Time: ~3–4 hours.

What you'll practise:

Setup: A terminal and bash/zsh (macOS, Linux, WSL). jq is required for script 4 — install per 00.2's Setup (brew install jq, sudo apt install jq, or winget install jqlang.jq). No Python needed, though script 5 may call git init if present. All scripts live in ~/code/ai-path/scripts/ (create it; add it to git per Starter A if that project is done).

Starter data — create ~/code/ai-path/data/ with these two files so the scripts have something real to chew on:

data/app.log (a web server's log; the same shape as the lesson's demo log):

text
2026-11-01T09:00:01Z INFO server started
2026-11-01T09:00:14Z DEBUG cache hit
2026-11-01T09:01:02Z ERROR db connection refused
2026-11-01T09:01:03Z WARN retrying db connection
2026-11-01T09:02:10Z INFO request served
2026-11-01T09:02:11Z ERROR db connection refused
2026-11-01T09:03:00Z INFO request served
2026-11-01T09:03:01Z ERROR db connection refused

data/tickets.json (the lesson's demo shape — request_id plus a tickets array):

json
{"request_id":"req-1042","tickets":[
 {"id":"T-101","subject":"cannot log in","status":"open","priority":"high"},
 {"id":"T-102","subject":"invoice question","status":"resolved","priority":"normal"},
 {"id":"T-103","subject":"site down","status":"open","priority":"urgent"},
 {"id":"T-104","subject":"feature request","status":"pending","priority":"low"}]}

Steps:

  1. summarize.sh LOG_FILE — for each of DEBUG INFO WARN ERROR, print the level and its line count (grep -c " LEVEL "), then total lines (wc -l). Loop over the levels, set -euo pipefail, quote "$LOG_FILE". This is 00.2 §8.3's summarize_errors.sh generalised — compare yours with the lesson's.
  2. bulk_rename.sh DIR PREFIX — rename every *.jpg in DIR matching img_NNN.jpg to PREFIX_NNN.jpg. Rehearse safely first: print each mv as a dry run unless --apply is passed (00.2 §9.3 and the rm rehearsal rule in §3.5). Use a for loop and ${name##*/}-style parameter expansion or basename; handle the "no matches" case gracefully.
  3. backup.sh SRC_DIR DEST_ROOT — copy SRC_DIR to DEST_ROOT/backup-YYYYMMDD-HHMMSS/ (timestamp via date +%Y%m%d-%H%M%S), then prune backups keeping the newest 5. Check SRC_DIR exists and DEST_ROOT is creatable before copying; never delete anything outside DEST_ROOT (00.2, file-safety rules).
  4. ticket_report.sh JSON_FILE — with jq: print request_id; the ticket count; counts per status (jq -r '.tickets[].status' | sort | uniq -c); and the id+subject of every open ticket (jq -r '.tickets[] | select(.status=="open") | "\(.id) \(.subject)"'). Guard with command -v jq and a friendly error if it's missing.
  5. new_project.sh NAME — scaffold ~/code/NAME/ with mkdir -p, a minimal README.md (title + one-line purpose placeholder), a .gitignore from 00.3 §4.1, a notes/ folder, and — if git exists — git init -b main. Refuse to run if the folder already exists (no silent overwrites). Heredocs (cat > file <<'EOF') are the tool; quote the delimiter so $ isn't expanded (00.2 §8.2).
  6. Write scripts/README.md — one paragraph per script: what it does, usage line, one example, and which lesson section taught each technique. Note honestly which parts are bash and which would become Python if they grew (00.2 §8.5).
  7. Rehearse the dangerous one. In a scratch folder, create fake img_001.jpg–img_003.jpg, run bulk_rename.sh dry-run then --apply, and prove a typo'd DEST_ROOT in backup.sh fails before deleting anything.

Verify it, and what you should see:

bash
chmod +x scripts/*.sh
scripts/summarize.sh data/app.log
scripts/ticket_report.sh data/tickets.json

summarize.sh prints the per-level counts and total — for the sample app.log above: DEBUG 1, INFO 3, WARN 1, ERROR 3, total 8 (order follows your loop). ticket_report.sh prints req-1042, 4 tickets, the status counts (open 2, pending 1, resolved 1) and the two open tickets T-101 cannot log in / T-103 site down. new_project.sh demo-app creates the folder tree and git status inside it reports a fresh repo on main. Every script exits non-zero with a readable message when given bad input — test summarize.sh /nonexistent.log.

Done when:

  • All five scripts run on your OS, are executable, and pass bash -n (syntax check) cleanly.
  • summarize.sh and ticket_report.sh produce the outputs above on the starter data.
  • bulk_rename.sh defaults to dry-run and only mutates with --apply; backup.sh prunes to 5 and refuses unsafe destinations.
  • new_project.sh refuses to overwrite an existing folder.
  • scripts/README.md documents usage and cites the lesson sections.
  • (If Starter A is done) each script was committed separately with a real message.

Stretch ideas: Add --help to each script (case "$1" in -h|--help) and a set -u-safe ${VAR:-default} pattern (00.2 §8.2). Make backup.sh verify the copy (diff -r or checksums) before pruning. Port summarize.sh's counting to jq over a JSONL log — the same skill that reads LLM traces in 11A.1. Honest limit: when a script needs real data structures or others must maintain it, that's the signal to move to Python — 00.2 §8.5 names the triggers, and Module 01A teaches the language.

Common problems:

  • Permission denied running ./summarize.sh → missing execute bit and shebang; chmod +x fixes the first, #!/usr/bin/env bash as line 1 the second (00.2 §6.3).
  • set -e kills the script on grep finding nothing → grep -c exits 1 on zero matches; use || true or grep -c ... || n=0 deliberately.
  • Filenames with spaces break loops → quote everything: "$f", "$DIR", and prefer while IFS= read -r over for f in $(ls) (00.2 §2.7).
  • jq: command not found → install it per Setup, or add a command -v jq guard with a clear message.
  • macOS vs Linux differences bite (sed -i, date, stat) → the lesson's BSD-vs-GNU callouts and cheat sheet exist for exactly this; test on your target OS.

Stretch

Stretch: A JSON API client, built from docs alone#

Goal: Integrate a service you have never used — the fictional ParcelPost shipping API — using only its documentation: read the reference like a professional, write a standard-library Python client, prove it against a fake server you write yourself, and keep a dated notes file of verified facts.

Time: ~4–6 hours — the fake server and the client are each roughly half the work.

What you'll practise:

  • The docs-site map and which page to read first (lesson 00.8, Part 1)
  • The reference-entry checklist: endpoint, parameters by location, request/response, errors, limits — and what the docs don't say (00.8, 2.1, 2.6)
  • Percent-encoding, headers, JSON bodies, status codes and error envelopes (00.6, Parts 1–2)
  • A stdlib urllib.request client and a stdlib http.server fake (00.6 §5.4, 00.8 §8.4–8.5)
  • Cursor pagination and the next_cursor: null end signal (00.6 §3.3)
  • Reading an OpenAPI document and diffing it against the prose docs (00.8, Part 3)
  • The source-reliability checklist, volatile facts and the notes-file habit (00.8, Part 5)

Setup: Python 3.11+ standard library only — urllib.request, json, http.server, threading. No API key: the "API key" is a placeholder the fake server accepts. Work in a scratch folder (e.g. ~/code/api-practice/parcelpost/) — this project deliberately lives outside ai-path until it works, then you may move it in.

The documentation (a condensed copy of 00.8 §8.2 with the same contract — the full text, including the error type table, is there; the essentials are reproduced here so the project stands alone):

ParcelPost API — Base URL https://api.parcelpost.example/v1; every request needs Authorization: Bearer <key> (pp_test_ keys); JSON in and out.

Method & path Purpose Parameters
GET /quotes Price a shipment query: to_postcode (required), weight_g int grams (required), service (optional, default standard)
POST /shipments Create a shipment body: to_postcode, weight_g (1–30000), service (optional) → 201 + shipment object {id, to_postcode, weight_g, service, status, price_pence, currency, tracking_url}
GET /shipments List shipments query: limit (default 2, max 5), cursor (optional); returns {items, next_cursor} — pass next_cursor back until it is null
GET /shipments/{id} Fetch one path id

service ∈ economy, standard, express. Errors are {"error": {"type", "code", "message", "request_id"}}: 400 malformed, 401 auth, 404 unknown route/id, 422 field violation (code names the rule). Rate limit 60 req/min; 429 → wait and retry. The vendor also publishes /openapi.json (00.8 §8.6 has the full document).

Steps:

  1. Read before you write. Spend fifteen minutes on the reference alone and write notes/reading-notes.md: the four endpoints, every parameter with its location and constraints, the error table, and — the important part — a "what the docs don't say" list (00.8 §8.3 models this: is price_pence taxed? is tracking_url stable? what status values exist beyond label_created?).
  2. Write the client from the docs. parcelpost_client.py: get_quote, create_shipment, get_shipment, list_shipments — stdlib only, urllib.parse.urlencode for query strings (postcodes contain spaces), a timeout on every call, and an ApiError carrying status/type/code/request_id (00.8 §8.4 has the full worked version to compare against after you've tried). Read PARCELPOST_URL/PARCELPOST_API_KEY from the environment, defaults for local testing.
  3. Write the fake server. parcelpost_server.py: a http.server.BaseHTTPRequestHandler on 127.0.0.1 with an ephemeral port (("127.0.0.1", 0)), in-memory shipment store starting empty, deterministic IDs (ship_0001, ship_0002, …), the documented validation (weight_g 1–30000 on both quote and create — the docs only restate it on POST, a real docs gap the lesson's spec reveals), cursor pagination honouring limit ≤ 5 and next_cursor: null, and the four documented error envelopes with incrementing request_ids. Compare with the lesson's server afterwards — yours should enforce the same contract.
  4. Prove it. demo.py: start the server in a daemon thread, set PARCELPOST_URL to its actual port before importing the client, then exercise every endpoint — a quote, three shipments to postcodes with spaces (SW1A 1AA, M1 1AE, EH1 1YZ), a fetch, two pages of list_shipments, and the three error paths (422 bad weight, 404 unknown id, 400 limit=99). Shut the server down at the end (00.8 §8.5).
  5. Diff prose vs spec. Save the OpenAPI document from 00.8 §8.6 as parcelpost_openapi.json, run the read_openapi.py script from 00.8 §3.2 on it, and write down every place the machine-readable spec says something the prose didn't (or vice versa).
  6. Keep the notes file. notes/parcelpost.md in the 00.8 §5.4 format: facts you verified against the running fake (with the date), facts taken from docs only, and an explicit "NOT verified" section. This file is the deliverable that transfers to real APIs later.
  7. Stretch within the project: add DELETE /shipments/{id} to your docs (write the reference section first, then implement server and client) — the exercise of writing docs before code is the skill.

Verify it, and what you should see:

bash
python3 demo.py

The lesson's own verified run of the same exercise produced (deterministic — your IDs and prices should match if you implemented the contract faithfully):

Output10 lines
quote: {'price_pence': 360, 'currency': 'GBP', 'eta_days': 3, 'service': 'express'}
created: ship_0001 label_created -> SW1A 1AA
created: ship_0002 label_created -> M1 1AE
created: ship_0003 label_created -> EH1 1YZ
track: https://track.parcelpost.example/ship_0001
page1 next_cursor: 2 ids: ['ship_0001', 'ship_0002']
page2 next_cursor: None ids: ['ship_0003']
error: 422 invalid_fields (request_id=req_0001)
error: 404 shipment_not_found (request_id=req_0002)
error: 400 bad_limit (request_id=req_0003)

If your output differs, the difference is information: a wrong price_pence means your quote formula differs from the spec; a next_cursor that never ends means you're looping on items instead of next_cursor; a missing request_id means your error envelope is incomplete.

Done when:

  • demo.py exercises all four endpoints plus the three documented error paths and prints the shape above.
  • Pagination stops on next_cursor: null — exactly two pages for three shipments at limit=2, with no extra empty-page request.
  • The client percent-encodes query parameters, sends Authorization: Bearer, sets Content-Type: application/json, uses a timeout, and raises a typed error carrying request_id.
  • Your fake server enforces the documented constraints — including the weight_g bound on GET /quotes that the prose never restated.
  • notes/parcelpost.md separates verified facts, docs-only facts and unverified questions, each dated.
  • You can name, from your reading notes, three things the documentation did not tell you.

Stretch ideas: Add the DELETE endpoint end-to-end (docs first). Add a retry-with-backoff wrapper for 429 using the four timeout types from 00.6 §1.9 — the real engineering is 01B.9 and 03.8. Generate a typed client skeleton from parcelpost_openapi.json and compare it with your hand-written one (00.8 §3.4). Point the same client code at a real free API later — the discipline is identical; only the docs URL changes.

Common problems:

  • URLError/Connection refused on import → PARCELPOST_URL must be set before parcelpost_client is imported (it reads env at module load); the lesson's demo ordering exists for this reason.
  • Postcode with a space breaks the URL → use urllib.parse.urlencode, never string-concatenate query params (00.6 §1.4).
  • list_shipments loops forever → you're checking items for emptiness; the contract is next_cursor: null (00.8 §8.3).
  • POST "fails" with 201 → 201 is success; only 2xx matters, and your client must accept it (00.6 §1.5).
  • The server port collides → bind ("127.0.0.1", 0) for an ephemeral port and read server_port — never hardcode 8765 in tests (00.2 §6.6).

Stretch (optional)

Stretch (optional): Contribute to an open source project#

Goal: Make one real, small contribution to an open-source project — ideally a documentation fix — following its CONTRIBUTING.md and issue conventions, and open a pull request a maintainer can actually merge.

Time: ~2–4 hours of your own work — plus maintainer latency, which you don't control (days to weeks is normal for a first-time contributor).

What you'll practise:

  • Fork vs branch-and-PR, and the upstream-remote dance (lesson 00.4, 4.2)
  • Writing a PR reviewers can review: what/why/how-I-tested (00.4, 4.3)
  • Code review as a skill, including reviewing generated code critically (00.4, 4.7)
  • Issues: labels, linking Fixes #N, good bug reports (00.4, Part 5)
  • Licences and provenance when touching other people's code (00.4 §6.6, 00.9 §5.4)
  • Asking well: minimal reproducible examples and the good question (00.9, 4.3–4.4)

Setup: needs a free GitHub account and gh (00.4 Setup). Everything else is the git you already know.

Steps:

  1. Pick the right first issue. Search GitHub for is:issue is:open label:"good first issue" in a project you genuinely use — documentation fixes, broken links, small test additions. Prefer issues with a linked CONTRIBUTING.md and recent maintainer activity. Read the issue and its comments before committing to it; if someone claimed it, pick another.
  2. Read the governance files first. CONTRIBUTING.md, CODE_OF_CONDUCT.md, the PR/issue templates in .github/, the licence, and one recently-merged PR to learn the house style (00.4 §6.1, §5.5). If the project asks you to open an issue before a PR, do that — some do, and skipping it is the fastest way to get ignored.
  3. Fork and branch. Fork on GitHub, gh repo clone your fork, git remote add upstream <original-url>, and branch off upstream/main (git fetch upstream && git switch -c fix/docs-typo-42 upstream/main) — never commit to your fork's main for the contribution itself.
  4. Make the smallest correct change. One issue, one PR, one logical change — atomic commits (00.3 §3.6). If you used an AI assistant for any of it, say so in the PR and verify every line yourself (00.9 §5.2); check the licence implications of copied code.
  5. Write the PR properly. Title in the project's style; body with What (links Fixes #42), Why, How I tested (00.4 §4.3). Attach screenshots or command output where relevant. Request review only if the project uses that flow.
  6. Respond to review like a professional. Maintainers may request changes, ask questions, or close the PR. Reply to every comment, push fixes as new commits (don't force-push over review feedback — 00.4 §4.5), and thank people. A graceful response to a rejected PR teaches you more than a merged one.
  7. Write it up. Add a notes/open-source-first-pr.md in ai-path: the issue, your PR link, what review taught you, and what you'd do differently. This is portfolio material for Module 14B.

Verify it, and what you should see: the verification is the PR itself — gh pr status shows it open (or merged/closed), CI checks (if the project has them) run on it, and at least one maintainer or bot interaction happens. A merged PR is the gold standard; a politely-reviewed-and-closed one still counts as done if you followed the process.

Done when:

  • You found the issue yourself via labels/search, read the governance files, and followed them.
  • Your PR is small, focused, well-described, and links the issue correctly.
  • You responded to every review comment professionally — including "no".
  • Your notes file records the lesson, not just the link.

Stretch ideas: After the first PR merges, pick a second, slightly larger issue. Review someone else's open PR and leave one genuinely useful comment (00.4 §4.7) — reviewing is the faster way to learn what good code looks like. If the project is AI-adjacent (an SDK, a docs site, an eval tool), say so — relevant open-source history is exactly what AI-engineering hiring managers look for.

Common problems:

  • PR ignored for weeks → you skipped CONTRIBUTING.md, picked a contested issue, or the PR is too big; read the merged-PR history to calibrate size.
  • CI fails on a docs typo → check the project's lint rules (markdownlint, link checkers) before pushing; run their checks locally first.
  • "Please open an issue first" → some projects require it; open the issue, wait for a maintainer's go-ahead, then PR.
  • Accidentally committed to the wrong remote/branch → git remote -v and git branch -vv are your friends; fix with a new branch, not history surgery, until you know 00.3 Part 6.

Stretch (optional)

Stretch (optional): Dotfiles and automation#

Goal: Turn your machine's configuration into a versioned, shareable repo — dotfiles with symlinks, a task runner for common commands, and a CI workflow that checks the repo on every push — the "adult" version of the setup habits from 00.1 and 00.2.

Time: ~3–4 hours, mostly in the sanitisation and the CI debugging.

What you'll practise:

  • Dotfiles as config you version (00.1 §3.3)
  • Startup files and what each shell reads (00.2, 5.4)
  • set -euo pipefail discipline and when scripts become Python (00.2, Part 8)
  • Makefile/task-runner thinking (00.2 §8.6)
  • GitHub Actions anatomy: on, jobs, steps, uses, run, secrets vs variables, pinning (00.4, Part 7)
  • Safe, reviewable automation instead of curl | sh (00.2 §9.3)

Setup: git and your shell of choice. The Makefile/just part works fully offline; the Actions part needs a free GitHub account and a repo to push to (reuse ai-path or make dotfiles public/private as you prefer — public gets secret scanning free, per 00.4 §8.1).

Steps:

  1. Inventory your dotfiles. List the config files your shell and tools actually read: ~/.zshrc or ~/.bashrc, ~/.gitconfig, ~/.gitignore_global, editor settings, ~/.ssh/config (structure only — never commit private keys or tokens). Read 00.2 §5.4 to know which file your shell reads when.
  2. Create the repo. git init dotfiles (in ~/code/ or a scratch area first), copy sanitised versions of your dotfiles into a home/ subfolder mirroring their real paths (home/.zshrc, home/.gitconfig, …). Add a README.md explaining the layout and the symlink strategy, plus an install script install.sh that creates symlinks (ln -sfn) from ~/ to the repo files — with a --dry-run flag that only prints what it would link.
  3. Move real config gradually. Start with the safest file (.gitignore_global or a shell alias block), symlink it, open a new terminal, verify it loads, then commit. One file per commit — atomic and reversible (00.3 §3.6). Never symlink .ssh wholesale; review every file for secrets before it enters git (00.4 §8.5–8.6).
  4. Write the task runner. A Makefile (installed everywhere) or justfile with targets for your real repeated tasks: make setup (run install.sh), make test (your project's checks), make lint, make clean. Each recipe is one shell command — this is where set -euo pipefail thinking applies to automation. Compare with the Makefile/just awareness in 00.2 §8.6; when recipes grow logic, that's the Python signal (§8.5).
  5. Add the CI workflow. .github/workflows/check.yml following 00.4 §7.2–7.3's anatomy: on: push + pull_request, one job, steps that check out the repo and run your checks — for this repo, a shellcheck-style syntax pass (bash -n on every *.sh), a "no secrets" grep for obvious placeholder patterns, and install.sh --dry-run succeeding. Pin actions by tag/SHA per §7.4; never echo secrets.
  6. Push and watch. Push the repo, open the Actions tab, and read a real run — green first try is rare; debug the workflow YAML itself (indentation, run vs uses, shell quoting) until it's green. This is your first CI loop, and it's deliberately tiny.

Verify it, and what you should see: locally, install.sh --dry-run prints the symlink plan without touching ~/; after install.sh, ls -la ~/ shows the symlinks and a new shell picks up your aliases. On GitHub, the Actions run for your latest commit shows a green check, and git log shows the workflow file itself versioned like everything else.

Done when:

  • At least three real dotfiles are versioned and symlinked, with install.sh reproducing the setup on a fresh account (test in a scratch $HOME if possible).
  • Makefile/justfile targets run your common tasks and are documented in the README.
  • The CI workflow is green on GitHub and actually checks something (syntax, secrets, dry-run) — not a no-op.
  • No secrets, keys or machine-specific paths are committed; the sanitisation is explained in the README.

Stretch ideas: Add a second machine profile (home-linux/ vs home-macos/) selected by uname. Add a bootstrap target that installs prerequisites idempotently (with the official install commands from 00.1, never curl | sh). Encrypt the truly-private dotfiles with git-crypt or age and document the key handling. Wire check_setup.py from 00.1 §7.2 into CI so a fresh Codespace self-verifies (00.1 §2.5).

Common problems:

  • New terminal doesn't see changes → startup files are read at shell start; open a new one, or source ~/.zshrc deliberately.
  • Symlink loops or wrong targets → install.sh must resolve the repo path absolutely and use ln -sfn; test with --dry-run first.
  • Workflow YAML fails with cryptic errors → YAML is whitespace-sensitive; validate indentation and check the run logs line by line — 00.4 §7.2 annotates every key.
  • Accidentally committed a token → rotate it first (00.4 §8.5), then clean history; the repo being private doesn't make it safe.
  • "It works on my machine" for the dotfiles themselves → that's the whole point of the project: if install.sh can't reproduce your setup from a clean checkout, the repo isn't done.
Esc
02.2Tokens and TokenizationHow LLMs Work · 21k wordsLesson
02.3EmbeddingsHow LLMs Work · 18k wordsLesson
07Retrieval-Augmented Generation (RAG)11 lessons · Everyone who will build LLM features that must answer from knowledge the model doesn't have in its weights: internal handbooks and help centres, contracts, ticket histories, product docs, or any corpus that changes faster than a training run. The module covers the full RAG stack — architecture, retrieval strategy, query understanding, grounded generation, citations, conversation, managed services, advanced patterns, evaluation, debugging and production operation — and shows where each major provider's managed retrieval and citation features fit (OpenAI, Anthropic, Google Gemini and OpenRouter). All code is Python.Overview
08E.1The Model Context Protocol (MCP)Protocols and Extensibility · 12k wordsLesson
↑ ↓ navigate↵ openesc close