DE Track — Capstone Labs
Back to W4 Ingestion Lab — API to Parquet to Warehouse

W4 Starter — fetch.py + load.py Skeleton

Starter code with TODOs; fill in retry, watermark, and atomic load logic.

4 minutesInteractive tutorial
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Outcome: fill the three TODO functions and pass all four self-checks below against the LOCAL fixture generator — no network, no hosted server.

# src/ingest/fetch.py
import time
from src.ingest.fixture import get_page  # LOCAL fixture, not a server

def fetch_page(resource: str, page: int, per_page: int = 100) -> dict:
    # TODO: call get_page(resource, page, per_page)
    # TODO: retry 3x with exponential backoff on 429/5xx
    #       (simulate: raise on first call for page 2, succeed on retry)
    raise NotImplementedError

def fetch_incremental(resource: str, since: str):
    # TODO: loop pages until an empty `data` list; skip rows with
    # updated_at <= since (watermark); write each page to
    # data/parquet/{resource}/page_{n}.parquet
    raise NotImplementedError
# src/ingest/load.py
import glob
import pandas as pd
from sqlalchemy import create_engine, text

def load_staging(resource: str, engine, watermark: str) -> int:
    # TODO: read data/parquet/{resource}/*.parquet
    # TODO: upsert into stg_{resource} on primary key inside ONE transaction
    # TODO: advance ingest_watermark to max(updated_at) only on success
    raise NotImplementedError

Self-checks before submitting (run in repo root)

  1. python -m src.ingest.fixture --check — prints FIXTURE OK (200 orders / 2 pages, unique ids, monotonic updated_at).
  2. Run fetch + load twice with no new data — staging counts identical the second time (idempotent re-run, ms 276 done_when).
  3. Mutate one fixture row (change status, bump updated_at past the watermark) and re-run — exactly one row changes.
  4. findings/01_ingestion.md records counts + watermark + re-run proof; kill a load mid-transaction and show the re-run reconciles in findings/02_failure_drill.md (ms 277).

No questions available for this tutorial.