Ingesting from an API: paginate, don't guess
Stage 1: extract. Most real data does not arrive as a file someone hands you — you fetch it. The National Weather Service API is free, needs no key, and answers in GeoJSON, which makes it ideal pipeline food. The ingest job has one responsibility: ask politely, page through everything, and hand over exactly what came back.
The code
import requests
HEADERS = {"User-Agent": "station-pipeline (learning project)"}
url = "https://api.weather.gov/stations/KNYC/observations"
params = {"start": "2026-11-12T00:00:00Z", "end": "2026-11-13T00:00:00Z"}
resp = requests.get(url, headers=HEADERS, params=params, timeout=30)
resp.raise_for_status() # fail loudly on HTTP errors
page = resp.json()
features = page["features"] # GeoJSON: one dict per observation
while page.get("pagination", {}).get("next"):
resp = requests.get(page["pagination"]["next"],
headers=HEADERS, timeout=30)
resp.raise_for_status()
page = resp.json()
features += page["features"]
print(len(features), "observations fetched")
In practice
Identify yourself. The User-Agent header is not decoration — the NWS requires one, and well-behaved APIs rate-limit anonymous clients harder. Saying who you are is the first rule of ingest etiquette.
Bound the request. The start/end parameters fetch exactly one day, so a rerun asks for the same window and gets the same data back. An unbounded 'give me everything' request is how pipelines fall over — and how duplicates are born (Lesson 36 returns to this).
Follow the pagination links. When a response is too big for one page, the API hands you a next URL. Follow it instead of guessing page numbers or offsets: the API is the source of truth for how its own pages chain. And raise_for_status() turns a silent empty result into a loud failure — in pipelines, loud is good.
Notice what ingest does not do: no cleaning, no typing, no dropping rows. It returns raw features, untouched. Landing them safely is tomorrow's lesson.
Python bridge: This is requests plus a while loop — the only new idea is treating the links the API gives you as the source of truth for paging.
Further reading
API Web Service — National Weather Service (the official NWS API documentation — endpoints, the GeoJSON format, and the User-Agent rule)
Try it
Practice question: The code above pulls observations for one station (KNYC). What changes if you want every station in New Jersey — and which part of the code stays exactly the same either way?
Show answer
Result: You change the entry point: fetch the station list first (the /stations endpoint filtered to state=NJ), then loop over station IDs calling the same observations request for each. What does not change is the plumbing — the headers, the timeout, raise_for_status(), and the pagination while-loop are identical for every endpoint. Ingest code is mostly source-independent plumbing; only the URL and the window parameters are source-specific.