Case study: late deliveries from an orders API
From: Carlos Mendez, Logistics
"We use two carriers, Northline and Swiftpost, and customers keep complaining about late parcels. The orders API has everything: a promised date per order and, once delivered, the delivery date. Some orders haven't shipped yet, so their shipping info is missing.
Which carrier is late more often? If it's a tie, I care more about how late."
Your answer: the carrier, with its late share as evidence.
This case study chains the API patterns with a comparison between groups. The data arrives in pages, some orders have no shipping info yet (None), and others are shipped but not delivered.
Decide what counts before you count: only delivered orders can be on time or late. A late share per carrier answers "how often", and average days late among late orders answers "how late".
api_get in the setup returns canned pages; the code is the same you'd write against a real API.
from datetime import date
promised, delivered = date(2026, 3, 4), date(2026, 3, 7)
max((delivered - promised).days, 0)
Out: 3. Early deliveries count as 0 days late, not negative.