6.1 · Real-world cases

Level 6 · In practice

6.1Real-world cases

Goal: see how the skills from levels 0 to 5 chain together on real cases.
Estimated time: 14 min · If you only have 5 min: read “The essentials in 30s” + the diagram.

The essentials in 30 seconds

  • Anchor: the expense tracker chains functions → dataclass + JSON → venv + pytest → FastAPI → Docker + CI all the way to deployment.
  • Automate: the weekly CSV report grafts pandas, a Matplotlib chart, cron with logs and email sending onto these fundamentals.
  • Deliver: rebuilt venv, pinned requirements, green tests and logs checked the first month.

Nabil thread — one year on: two projects running in Algiers

Nabil, junior data analyst in Algiers, looks back on his two landmark projects of the year: the expense tracker born as a console notebook turned into a deployed API, then the fully automated weekly sales CSV report. Both cases below replay his sequence: break down, type, test, isolate, deliver.

Each case follows the Context → Steps → Result flow: replay it on your own projects.

Putting the bricks end to end

The previous levels laid the bricks (basics, structures, OOP, errors, modules, venv, tests, web, data, deployment); here we assemble them under real conditions: starting from a concrete need, we break down, type, test, isolate and deliver. Two cases played out from A to Z.

Case 1 — Expense tracker: from notebook to deployed API

Context: The thread project: an expense tracker born as a console notebook (N1), made persistent (N2), tested (N3), exposed as an API (N4) and deployed (N5).

Déroulé :

  1. N1: add/list/total functions, main() menu, 80 lines broken down.
  2. N2: Expense dataclass, JSON via pathlib, try/except on input.
  3. N3: modules + venv + requirements, hints, pytest tests of the total.
  4. N4: FastAPI (GET/POST) to expose expenses.
  5. N5: slim Dockerfile, ruff + pytest CI, deployment on every push.

Result: A URL listing your expenses, tested in CI, redeployed on every push.

Case 2 — Automated weekly report from a CSV

Context: Every Monday, a sales CSV export must become a figures summary sent by email.

Déroulé :

  1. pandas: read, inspect (isna), group by city, top 5.
  2. Matplotlib: one message-titled bar chart, PNG export.
  3. Scheduled script (cron) with logging + targeted try blocks, tested on copies.
  4. Email of the summary + PNG attached, logs checked the first month.

Result: Zero manual Mondays: the report arrives on its own, with its logs.

Common misinterpretation: “copying the cases identically”. No. The cases show an assembly order (break down, type, test, isolate, deliver), not a recipe to copy: reuse the order, adapt the data, framework and hosting to your project.
Text version of the diagram (SEO / screen readers / translation): Full chain: 1) Break down (short functions, main, modules). 2) Persist (dataclass, pathlib, JSON, targeted try). 3) Isolate and prove (venv, pinned requirements, hints, pytest). 4) Expose (FastAPI GET/POST). 5) Automate (pandas groupby, Matplotlib, cron, logging). 6) Deliver (slim Dockerfile, ruff + pytest CI, deployment, logs checked). Lesson: the break down → type → test → isolate → deliver sequence separates an application that runs from a script you no longer dare touch.

Ready-to-say script — scoping a Python project before coding (30 s)

“Our need: [expense tracker exposed as an API]. Our foundations: [broken-down functions + hints + pytest + venv]. We persist in JSON, expose with FastAPI, deliver via Docker + CI.”

Copy-paste template — minimal tracking API (FastAPI)

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()
depenses: list[dict] = []


class Depense(BaseModel):
    motif: str
    montant: float


@app.get("/depenses")
def lister() -> list[dict]:
    return depenses


@app.post("/depenses", status_code=201)
def ajouter(depense: Depense) -> dict:
    item = depense.model_dump()
    depenses.append(item)
    return item

VSE / small budget

Replay a single case on a simple need: single-resource tracker, minimal CSV report, direct deployment.

SME Algiers

Adapt deployment to local realities: shared workstations, Monday peaks, backups and a named contact.

Remote / hybrid

Double traceability at a distance: documented pinned requirements, CI pipeline and written access.

Intercultural

Check local usages before transposing a case: labels, cities and grouping rules must speak to the team.

Caution: General reminder: secrets (email keys, cloud tokens) and user data engage your liability — keep them in never-versioned environment variables, regenerate any exposed key and have the designated contact validate; this guide gives no legal advice.

48h challenge — apply tomorrow

Take 1 real project and write its chain in 5 steps (break down → type → test → isolate → deliver). Identify the next step.

Section exit checklist
  • I can assemble the bricks into a complete application, from notebook to deployed API.
  • I have a replayable FastAPI template for my project.
  • I did the 48h challenge or scheduled its date.
Self-assessment 1-5: chaining the steps?automation and delivery covered?
Check your understanding

Nabil grows his expense tracker into a deployed API. Which sequence follows the guide?