congress-trading / recipe.py
ZipLime's picture
Add ziplime PIT dataset: docs, manifest, recipe, ingest, workflow, bundle
ee6392b verified
Raw
History Blame Contribute Delete
1.84 kB
"""
US Congress Trading Disclosures (PIT) — collection recipe.
Contract (ziplime PIT recipe, design doc §9):
async def fetch(since: datetime) -> pl.DataFrame
Returns rows in the PIT schema for `congress-trading`:
system: entity_id, event_date, knowledge_date, knowledge_estimated
values: representative, chamber, transaction_type, asset_ticker, amount_low, amount_high, disclosure_lag_days
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
# House: disclosures-clerk.house.gov | Senate: efdsearch.senate.gov
rows = []
for chamber, endpoint in CHAMBER_ENDPOINTS.items():
resp = httpx.get(endpoint, params={"since": since.date().isoformat()}, timeout=60)
for f in resp.json()["filings"]:
rows.append({
"entity_id": f["ticker"],
"event_date": f["transaction_date"],
"knowledge_date": f["filed_at"] or _statutory_cap(f["transaction_date"]),
"knowledge_estimated": f["filed_at"] is None,
"representative": f["member"],
"chamber": chamber,
"transaction_type": f["type"],
"asset_ticker": f["ticker"],
"amount_low": f["amount_range"][0],
"amount_high": f["amount_range"][1],
"disclosure_lag_days": f["lag_days"],
})
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())