6.1Real-world cases
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é :
- N1: add/list/total functions, main() menu, 80 lines broken down.
- N2: Expense dataclass, JSON via pathlib, try/except on input.
- N3: modules + venv + requirements, hints, pytest tests of the total.
- N4: FastAPI (GET/POST) to expose expenses.
- 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é :
- pandas: read, inspect (isna), group by city, top 5.
- Matplotlib: one message-titled bar chart, PNG export.
- Scheduled script (cron) with logging + targeted try blocks, tested on copies.
- Email of the summary + PNG attached, logs checked the first month.
Result: Zero manual Mondays: the report arrives on its own, with its logs.
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.
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.
- 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.
Nabil grows his expense tracker into a deployed API. Which sequence follows the guide?