Download tools/fred.py from 1990two/XTOOLS: direct link, hf CLI and curl.
- Browser
- Download file 855 Bytes
-
https://huggingface.co/spaces/1990two/XTOOLS/resolve/main/tools/fred.py
- Command line
-
hf download hf://spaces/1990two/XTOOLS/tools/fred.py
-
curl -L -o fred.py https://huggingface.co/spaces/1990two/XTOOLS/resolve/main/tools/fred.py
855 Bytes
| """ | |
| FRED (Federal Reserve Economic Data) -- free instant-signup API key. | |
| """ | |
| import httpx | |
| from supabase_client import require_tool_keys | |
| def run(params: dict) -> dict: | |
| creds = require_tool_keys("fred") | |
| api_key = creds["api_key"] | |
| series_id = params.get("series_id") | |
| if not series_id: | |
| raise ValueError("series_id is required") | |
| resp = httpx.get( | |
| "https://api.stlouisfed.org/fred/series/observations", | |
| params={"series_id": series_id, "api_key": api_key, "file_type": "json"}, | |
| timeout=15.0, | |
| ) | |
| resp.raise_for_status() | |
| data = resp.json() | |
| observations = [ | |
| {"date": o["date"], "value": o["value"]} | |
| for o in data.get("observations", []) | |
| if o.get("value") not in (None, ".") | |
| ] | |
| return {"series_id": series_id, "count": len(observations), "results": observations} | |