""" Macro Indicators — Vintage / PIT (FRED-style) — collection recipe. Contract (ziplime PIT recipe, design doc §9): async def fetch(since: datetime) -> pl.DataFrame Returns rows in the PIT schema for `macro-indicators`: system: entity_id, event_date, knowledge_date, knowledge_estimated values: series_value, unit, native_frequency, release_kind The shared harness (ingest.py) stamps `ingested_at`, dedups against existing rows and appends to the Delta bundle. This recipe only fetches and shapes. """ from __future__ import annotations from datetime import datetime, timezone async def fetch(since: datetime): import polars as pl # noqa: F401 import httpx import polars as pl rows = [] for series in SERIES_CODES: # ALFRED returns every vintage (real-time period) for the series obs = httpx.get(ALFRED_URL, params={"series_id": series, "since": since.date().isoformat()}, timeout=60).json()["observations"] for o in obs: rows.append({ "entity_id": series, "event_date": o["period"], "knowledge_date": o["realtime_start"], # when this vintage was released "knowledge_estimated": False, "series_value": o["value"], "unit": o["unit"], "native_frequency": o["frequency"], "release_kind": o["release_kind"], }) return pl.DataFrame(rows) if __name__ == "__main__": import asyncio, polars as pl df = asyncio.run(fetch(datetime(2025, 1, 1, tzinfo=timezone.utc))) print(df.head())