FRED API Client

0.5.2 · active · verified Sat Apr 11

fredapi is a Python API for Federal Reserve Economic Data (FRED) from the St. Louis Fed, and also provides methods for analyzing point-in-time data from ALFRED. It leverages pandas for data output, returning data as Series or DataFrames. The current version is 0.5.2, with a release cadence of a few updates per year, primarily addressing Python and dependency compatibility.

Warnings

Install

Imports

Quickstart

Initialize the Fred client with your API key, then fetch or search for economic data series. Data is returned as a pandas Series or DataFrame.

import os
from fredapi import Fred

# Get a FRED API key from https://fred.stlouisfed.org/docs/api/api_key.html
# Set it as an environment variable or pass directly.
api_key = os.environ.get('FRED_API_KEY', 'YOUR_FRED_API_KEY')

if not api_key or api_key == 'YOUR_FRED_API_KEY':
    print("Warning: FRED_API_KEY environment variable not set or placeholder used. Get a key from fred.stlouisfed.org.")
    # Using a dummy key to allow the example to run without immediate error,
    # but API calls will fail without a valid key.
    api_key = 'abcdefghijklmnopqrstuvwxyz123456'

fred = Fred(api_key=api_key)

# Fetch a specific economic data series (e.g., S&P 500)
data = fred.get_series('SP500')

print("Fetched S&P 500 data (last 5 entries):")
print(data.tail())

# Search for data series
search_results = fred.search('unemployment rate')
print("\nSearch results for 'unemployment rate' (first 3):")
print(search_results[['id', 'title']].head(3))

view raw JSON →