Advanced Pilot

Designing Reliable Libraries

Design code that other developers can use correctly.

7 days · About 2 hours a day

Start Day 1

This 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. 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.

    1. 1.1 Names, Objects and Identity
    2. 1.2 Copying, Shallow and Deep
    3. 1.3 Where Attributes Come From
    4. 1.4 A Model That Saves Itself
  2. 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

    1. 2.1 Descriptors: Attributes With Behaviour
    2. 2.2 Fields That Refuse Bad Values
    3. 2.3 __init_subclass__ and What Happens at class
    4. 2.4 Day 2 Checkpoint: Fields in the Library
  3. 3

    Typed Interfaces & API Design

    Needs Python on your machine

    By 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.

    1. 3.1 Typing a Descriptor
    2. 3.2 Protocols: Say What You Use
    3. 3.3 Changing an API Without Breaking Callers
    4. 3.4 Day 3 Checkpoint: What the Checker Can't See
  4. 4

    Failing Safely

    By the end you can: Roll back on error, give the library its own exception hierarchy, and test the failure paths.

    1. 4.1 An Exception Hierarchy of Your Own
    2. 4.2 All or Nothing: Transactions
    3. 4.3 Testing the Paths That Fail
    4. 4.4 Day 4 Checkpoint: Write the Transaction
  5. 5

    Async Concurrency

    Standalone exercise Optional part needs local Python

    By 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

    1. 5.1 Tasks, Groups and Exception Groups
    2. 5.2 Bounding Concurrency
    3. 5.3 Cancellation and Cleanup
    4. 5.4 Day 5 Checkpoint: Backpressure and the Leak
  6. 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

    1. 6.1 Measuring Before Optimising
    2. 6.2 The Slow Path: One Query at a Time
    3. 6.3 Memory: Finding What Never Goes Away
    4. 6.4 Day 6 Checkpoint: Batch and Bound

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