Loading...
Loading...
Query FRED (Federal Reserve Economic Data) API for 800,000+ economic time series from 100+ sources. Access GDP, unemployment, inflation, interest rates, exchange rates, housing, and regional data. Use for macroeconomic analysis, financial research, policy studies, economic forecasting, and academic research requiring U.S. and international economic indicators.
npx skill4agent add k-dense-ai/claude-scientific-skills fred-economic-dataexport FRED_API_KEY="your_32_character_key_here"import os
os.environ["FRED_API_KEY"] = "your_key_here"from scripts.fred_query import FREDQuery
# Initialize with API key
fred = FREDQuery(api_key="YOUR_KEY") # or uses FRED_API_KEY env var
# Get GDP data
gdp = fred.get_series("GDP")
print(f"Latest GDP: {gdp['observations'][-1]}")
# Get unemployment rate observations
unemployment = fred.get_observations("UNRATE", limit=12)
for obs in unemployment["observations"]:
print(f"{obs['date']}: {obs['value']}%")
# Search for inflation series
inflation_series = fred.search_series("consumer price index")
for s in inflation_series["seriess"][:5]:
print(f"{s['id']}: {s['title']}")import requests
import os
API_KEY = os.environ.get("FRED_API_KEY")
BASE_URL = "https://api.stlouisfed.org/fred"
# Get series observations
response = requests.get(
f"{BASE_URL}/series/observations",
params={
"api_key": API_KEY,
"series_id": "GDP",
"file_type": "json"
}
)
data = response.json()| Series ID | Description | Frequency |
|---|---|---|
| GDP | Gross Domestic Product | Quarterly |
| GDPC1 | Real Gross Domestic Product | Quarterly |
| UNRATE | Unemployment Rate | Monthly |
| CPIAUCSL | Consumer Price Index (All Urban) | Monthly |
| FEDFUNDS | Federal Funds Effective Rate | Monthly |
| DGS10 | 10-Year Treasury Constant Maturity | Daily |
| HOUST | Housing Starts | Monthly |
| PAYEMS | Total Nonfarm Payrolls | Monthly |
| INDPRO | Industrial Production Index | Monthly |
| M2SL | M2 Money Stock | Monthly |
| UMCSENT | Consumer Sentiment | Monthly |
| SP500 | S&P 500 | Daily |
fred/seriesfred/series/observationsfred/series/searchfred/series/updates# Get observations with transformations
obs = fred.get_observations(
series_id="GDP",
units="pch", # percent change
frequency="q", # quarterly
observation_start="2020-01-01"
)
# Search with filters
results = fred.search_series(
"unemployment",
filter_variable="frequency",
filter_value="Monthly"
)references/series.mdfred/categoryfred/category/childrenfred/category/series# Get root categories (category_id=0)
root = fred.get_category()
# Get Money Banking & Finance category and its series
category = fred.get_category(32991)
series = fred.get_category_series(32991)references/categories.mdfred/releasesfred/releases/datesfred/release/series# Get upcoming release dates
upcoming = fred.get_release_dates()
# Get GDP release info
gdp_release = fred.get_release(53)references/releases.md# Find series with multiple tags
series = fred.get_series_by_tags(["gdp", "quarterly", "usa"])
# Get related tags
related = fred.get_related_tags("inflation")references/tags.md# Get all sources
sources = fred.get_sources()
# Get Federal Reserve releases
fed_releases = fred.get_source_releases(source_id=1)references/sources.md# Get state unemployment data
regional = fred.get_regional_data(
series_group="1220", # Unemployment rate
region_type="state",
date="2023-01-01",
units="Percent",
season="NSA"
)
# Get GeoJSON shapes
shapes = fred.get_shapes("state")references/geofred.md| Value | Description |
|---|---|
| Levels (no transformation) |
| Change from previous period |
| Change from year ago |
| Percent change from previous period |
| Percent change from year ago |
| Compounded annual rate of change |
| Continuously compounded rate of change |
| Continuously compounded annual rate of change |
| Natural log |
# Get GDP percent change from year ago
gdp_growth = fred.get_observations("GDP", units="pc1")| Code | Frequency |
|---|---|
| Daily |
| Weekly |
| Monthly |
| Quarterly |
| Annual |
avgsumeop# Convert daily to monthly average
monthly = fred.get_observations(
"DGS10",
frequency="m",
aggregation_method="avg"
)# Get GDP as it was reported on a specific date
vintage_gdp = fred.get_observations(
"GDP",
realtime_start="2020-01-01",
realtime_end="2020-01-01"
)
# Get all vintage dates for a series
vintages = fred.get_vintage_dates("GDP")def get_economic_snapshot(fred):
"""Get current values of key indicators."""
indicators = ["GDP", "UNRATE", "CPIAUCSL", "FEDFUNDS", "DGS10"]
snapshot = {}
for series_id in indicators:
obs = fred.get_observations(series_id, limit=1, sort_order="desc")
if obs.get("observations"):
latest = obs["observations"][0]
snapshot[series_id] = {
"value": latest["value"],
"date": latest["date"]
}
return snapshotdef compare_series(fred, series_ids, start_date):
"""Compare multiple series over time."""
import pandas as pd
data = {}
for sid in series_ids:
obs = fred.get_observations(
sid,
observation_start=start_date,
units="pc1" # Normalize as percent change
)
data[sid] = {
o["date"]: float(o["value"])
for o in obs["observations"]
if o["value"] != "."
}
return pd.DataFrame(data)def get_upcoming_releases(fred, days=7):
"""Get data releases in next N days."""
from datetime import datetime, timedelta
end_date = datetime.now() + timedelta(days=days)
releases = fred.get_release_dates(
realtime_start=datetime.now().strftime("%Y-%m-%d"),
realtime_end=end_date.strftime("%Y-%m-%d"),
include_release_dates_with_no_data="true"
)
return releasesdef map_state_unemployment(fred, date):
"""Get unemployment by state for mapping."""
data = fred.get_regional_data(
series_group="1220",
region_type="state",
date=date,
units="Percent",
frequency="a",
season="NSA"
)
# Get GeoJSON for mapping
shapes = fred.get_shapes("state")
return data, shapesresult = fred.get_observations("INVALID_SERIES")
if "error" in result:
print(f"Error {result['error']['code']}: {result['error']['message']}")
elif not result.get("observations"):
print("No data available")
else:
# Process data
for obs in result["observations"]:
if obs["value"] != ".": # Handle missing values
print(f"{obs['date']}: {obs['value']}")references/series.mdreferences/categories.mdreferences/releases.mdreferences/tags.mdreferences/sources.mdreferences/geofred.mdreferences/api_basics.mdscripts/fred_query.pyFREDQueryscripts/fred_examples.pyuv run python scripts/fred_examples.py