Advanced
Advanced & Idiomatic
Tier 5 — the tools and mental models that turn working Python into idiomatic, production Python. Type hints and mypy, the high-leverage standard library, the data model as one unified design, concurrency and the GIL, async foundations and async in practice, performance and profiling, and testing and packaging.
Suggest an editAdvanced & Idiomatic Python
By now you can build real programs. Tier 5 is about building them well — typed, tested, fast where it matters, concurrent where it helps, and shipped so others can run them. The thesis of the tier: idiomatic Python is mostly knowing which tool the language and standard library already give you — a type checker, the right container, the data-model protocol, the correct concurrency model, a profiler, a test runner — instead of reinventing them.
Eight chapters, in order:
- Type Hints & Static Typing — annotations,
Protocol, andmypy; documentation the tools can check (but the runtime ignores). - Standard-Library Tour —
collections,itertools,functools: the high-leverage batteries. - The Data Model — every operator and built-in is a dunder; your objects plug into the language.
- Concurrency: Threads, Processes & the GIL — what threads and processes actually are, what the GIL protects and when it lets go, locks and queues, and the free-threaded future.
- Async Python — cooperative single-threaded concurrency: coroutines as resumable frames and the event loop's actual algorithm.
- Async in Practice — tasks,
TaskGroup, failure modes, timeouts and cancellation, async iteration, and the queue pipeline. - Performance, Profiling & Memory — measure, don't guess; complexity dominates;
cProfileand__slots__. - Testing, Debugging & Packaging —
pytest, logging, virtual environments, and shipping withpyproject.toml.
These draw on everything before — especially the object model, dunder methods (which The Data Model synthesizes), and complexity. A note on the runnable blocks: a few topics here use tools the in-browser sandbox can't fully run (mypy, pytest, multiprocessing) — those are shown as clearly-labelled static examples, while everything testable in one Python file (threads, async, __slots__, timeit, the data model) is runnable and verified.
📘 How to read the Intuition boxes. Each one is built in three moves:
- The mechanism — what the interpreter is actually doing.
- A concrete bite — a specific, runnable way the naive assumption fails.
- The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.
This is the final tier. If you've read from Tier 0 to here, you've gone from "what is a program?" to typing, concurrency, and the data model — and, more importantly, you can now re-derive Python's behaviour from a handful of generative ideas rather than memorising it. That was the whole point.