DEV Community

Alex Spinov
Alex Spinov

Posted on

FRED API: Access 800,000+ Economic Datasets for Free (Inflation, GDP, Unemployment)

I was arguing with a coworker about whether inflation was actually going down. Instead of googling random charts, I pulled real Federal Reserve data in 30 seconds.

Here's how you can do the same.

What is FRED?

FRED (Federal Reserve Economic Data) is maintained by the St. Louis Fed. It has 816,000+ time series covering:

  • Inflation (CPI, PCE)
  • GDP and economic growth
  • Unemployment rates
  • Interest rates
  • Housing prices
  • And basically every economic indicator you can think of

Free API key — takes 30 seconds to get one at fred.stlouisfed.org.

Setup

import requests
from datetime import datetime

API_KEY = "your_free_api_key_here"  # Get at fred.stlouisfed.org/docs/api/api_key.html
BASE = "https://api.stlouisfed.org/fred"

def fred_get(endpoint, **params):
    params["api_key"] = API_KEY
    params["file_type"] = "json"
    return requests.get(f"{BASE}/{endpoint}", params=params).json()
Enter fullscreen mode Exit fullscreen mode

Get Inflation Data (CPI)

# CPIAUCSL = Consumer Price Index for All Urban Consumers
data = fred_get("series/observations", 
    series_id="CPIAUCSL",
    observation_start="2020-01-01",
    frequency="m"  # monthly
)

for obs in data["observations"][-6:]:
    print(f"{obs["date"]}: {obs["value"]}")

# 2024-10-01: 315.664
# 2024-11-01: 316.437
# 2024-12-01: 317.269
# 2025-01-01: 317.671
Enter fullscreen mode Exit fullscreen mode

Calculate Year-over-Year Inflation

def yoy_inflation(series_id="CPIAUCSL", periods=12):
    data = fred_get("series/observations",
        series_id=series_id,
        observation_start="2023-01-01",
        frequency="m"
    )
    obs = [(o["date"], float(o["value"])) for o in data["observations"] if o["value"] != "."]

    print("Month       | CPI     | YoY Inflation")
    print("-" * 42)
    for i in range(periods, len(obs)):
        date = obs[i][0]
        current = obs[i][1]
        year_ago = obs[i - 12][1]
        inflation = (current - year_ago) / year_ago * 100
        print(f"{date} | {current:.1f} | {inflation:.2f}%")

yoy_inflation()
# 2025-01-01 | 317.7 | 2.97%
Enter fullscreen mode Exit fullscreen mode

That's how I won the argument. Real data > opinions.

Search 800,000+ Datasets

def search_series(query, limit=5):
    data = fred_get("series/search",
        search_text=query,
        limit=limit,
        order_by="popularity",
        sort_order="desc"
    )
    for s in data["seriess"]:
        print(f"{s["id"]:20s} | {s["title"][:60]} | Pop: {s["popularity"]}")

search_series("housing prices")
# MSPUS              | Median Sales Price of Houses Sold    | Pop: 86
# CSUSHPISA          | S&P/Case-Shiller Home Price Index    | Pop: 79
Enter fullscreen mode Exit fullscreen mode

GDP Growth Tracker

def gdp_tracker():
    data = fred_get("series/observations",
        series_id="GDP",
        observation_start="2020-01-01",
        frequency="q"  # quarterly
    )
    obs = [(o["date"], float(o["value"])) for o in data["observations"] if o["value"] != "."]

    for i in range(1, len(obs)):
        growth = (obs[i][1] - obs[i-1][1]) / obs[i-1][1] * 100
        emoji = "📈" if growth > 0 else "📉"
        print(f"{obs[i][0]}: ${obs[i][1]:,.0f}B | {growth:+.2f}% {emoji}")

gdp_tracker()
Enter fullscreen mode Exit fullscreen mode

Unemployment Dashboard

def unemployment_vs_inflation():
    # Get both series
    unemp = fred_get("series/observations", series_id="UNRATE", observation_start="2023-01-01", frequency="m")
    cpi = fred_get("series/observations", series_id="CPIAUCSL", observation_start="2023-01-01", frequency="m")

    unemp_data = {o["date"]: o["value"] for o in unemp["observations"]}
    cpi_data = {o["date"]: o["value"] for o in cpi["observations"]}

    print("Date        | Unemployment | CPI")
    for date in sorted(set(unemp_data) & set(cpi_data))[-6:]:
        print(f"{date} | {unemp_data[date]}%          | {cpi_data[date]}")

unemployment_vs_inflation()
Enter fullscreen mode Exit fullscreen mode

Popular Series IDs (Bookmark These)

Series ID What it tracks
CPIAUCSL Consumer Price Index (inflation)
GDP Gross Domestic Product
UNRATE Unemployment Rate
FEDFUNDS Federal Funds Rate
DGS10 10-Year Treasury Rate
MSPUS Median Home Sale Price
SP500 S&P 500 Index
M2SL M2 Money Supply
DEXUSEU USD/EUR Exchange Rate

Why FRED > Random Charts on Twitter

  1. Source of truth — this IS the Federal Reserve's data
  2. 816,000+ series — if it's economic, FRED has it
  3. Historical data — some series go back to 1947
  4. Free — no paywall, no premium tier
  5. Updated in real-time — as soon as data is released

What economic question would you answer with this data?

I'm building a series on free government APIs (SEC EDGAR was yesterday). Drop a comment with which API you want next.


Follow for daily tutorials on free APIs and developer tools.

Top comments (0)