Writing Reliable Python
Make programs that survive bad input and stay easy to change.
7 days · About 2 hours a day
Start Day 1This course is in its pilot. All seven days are ready to work through. How long each lesson took you, and where you got stuck, decides what changes before it's final.
How it works
- Seven days is a pace, not a deadline. Each day is a module; taking one over two sittings costs nothing.
- Core first. A day's Optional topics — sections headed Going further, and asides — are extras nothing later depends on. Skip them on a first pass.
- Help comes in steps. Every exercise has hints — the idea, then a first step — before its solution.
- Then on your own. The course ends with a fresh brief to build without a plan, and review challenges to come back to a week and a month later.
The seven days
- 1
Refactoring with a Safety Net
By the end you can: Split a messy working script into small, well-defined functions, with tests locking in its behaviour before anything changes.
- 2
Parsing Text
By the end you can: Turn raw log lines into dataclass records — string methods where they're enough, a regex where the format needs one — stream the file lazily, and reject malformed lines with clear errors.
Optional: Pattern matching on parsed records
- 3
Storing Data
By the end you can: Store records in SQLite with parameterized queries, test against an in-memory database, and save a summary as JSON.
Optional: Custom JSON encoders
- 4
Functions & Resources
By the end you can: Make the analyzer configurable by passing functions, and guarantee cleanup with `with` — proven by a test. A decorator only if something genuinely repeats.
Optional: Decorators and decorator factories · functools.partial and singledispatch
- 5
Composition & Practical Typing
Optional part needs local PythonBy the end you can: Compose records into reports, type-hint the public functions, and fix a silent miscount — deciding yourself whether an Enum is the right cure.
Optional: Protocols · Running mypy
- 6
Async Fundamentals
Standalone exercise Optional part needs local PythonBy the end you can: Fetch several simulated sources at once with asyncio, handling a timeout and one failing source.
Optional: Threads and processes · Real HTTP requests
- 7
Finish & Ship
Optional part needs local PythonBy the end you can: Finish the analyzer: tests for the week's edge cases, logging, a README and an argparse command line.
Optional: Packaging and installing it