Designing Reliable Libraries
Design code that other developers can use correctly.
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
The Object Model
By the end you can: Predict references, copying and attribute lookup; build a Model that saves and loads a record through supplied SQLite scaffolding; find a bug where instances share state.
- 2
Descriptors & Class Customisation
By the end you can: Replace plain attributes with validating field descriptors, and register models with __init_subclass__ — improving a model that already works.
Optional: Metaclasses, and why they weren't needed
- 3
Typed Interfaces & API Design
Needs Python on your machineBy the end you can: Type the library so a checker catches misuse — wrong types, missing fields, deprecated calls — and say precisely what it cannot catch.
- 4
Failing Safely
By the end you can: Roll back on error, give the library its own exception hierarchy, and test the failure paths.
- 5
Async Concurrency
Standalone exercise Optional part needs local PythonBy the end you can: Bound concurrency, clean up on cancellation and apply backpressure with queues, on simulated I/O.
Optional: Threads, the GIL and free-threading
- 6
Performance & Memory
By the end you can: Find a slow path and a memory leak in the library with cProfile and tracemalloc, using workloads big enough to measure.
Optional: Bytecode and dis
- 7
Integrate & Explain
By the end you can: Finish, test and benchmark the library, and write up its design trade-offs.
Optional labs
Ideas for deeper dives outside the seven days — sketches to explore on your own, not lessons in the course.
- Build a tiny event loop
- Import hooks
- A t-string query processor — where safety comes from the processor, not the syntax