FRED Economic Data Tools for LLM/Agent Integration - Access 800,000+ Federal Reserve time series
Project description
fred-toolkit
FRED Economic Data Tools for LLM/Agent Integration
A Python package providing LLM-compatible tools for accessing 800,000+ Federal Reserve Economic Data (FRED) time series. Perfect for building AI agents, chatbots, and automated analysis systems that need access to economic data.
Note: This package is converted from the FRED MCP Server but designed as a lightweight Python library without server deployment overhead.
Features
✅ 3 Powerful Tools for comprehensive FRED data access
✅ OpenAI-Compatible function calling format
✅ Works with any LLM (OpenAI, Anthropic, local models)
✅ No server required - pure Python library
✅ 800,000+ time series from Federal Reserve
✅ Pythonic API for direct usage
Installation
pip install fred-toolkit
Or with uv:
uv pip install fred-toolkit
Quick Start
1. Get your FRED API Key
Get a free API key from: https://fred.stlouisfed.org/docs/api/api_key.html
2. Basic Usage with LLM
from fred_toolkit import FredTools
import openai
import json
# Initialize
fred = FredTools(api_key="your-fred-api-key")
client = openai.OpenAI()
# Get tool definitions
tools = fred.get_tool_definitions()
# Send to LLM
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "What's the current US unemployment rate?"}],
tools=tools
)
# Execute the tool LLM chose
tool_call = response.choices[0].message.tool_calls[0]
result = fred.execute_tool(
tool_call.function.name,
json.loads(tool_call.function.arguments)
)
print(result)
3. Direct Python Usage
from fred_toolkit import FredTools
fred = FredTools(api_key="your-fred-api-key")
# Search for series
results = fred.search("unemployment")
print(results)
# Get specific series data
data = fred.get_series("UNRATE", observation_start="2020-01-01")
print(data)
# Browse categories
categories = fred.browse(browse_type="categories")
print(categories)
Available Tools
fred_search
Search for FRED economic data series by keywords, tags, or filters.
Example:
result = fred.execute_tool("fred_search", {
"search_text": "inflation",
"limit": 10
})
fred_get_series
Retrieve data for any FRED series with transformations and date ranges.
Example:
result = fred.execute_tool("fred_get_series", {
"series_id": "GDP",
"observation_start": "2020-01-01"
})
fred_browse
Browse FRED's catalog through categories, releases, or sources.
Example:
result = fred.execute_tool("fred_browse", {
"browse_type": "categories"
})
Common Use Cases
Building an Economic Analysis Agent
def ask_fred(user_query: str) -> str:
"""Complete agent loop with automatic tool selection"""
fred = FredTools(api_key="...")
client = openai.OpenAI()
messages = [{"role": "user", "content": user_query}]
response = client.chat.completions.create(
model="gpt-4",
messages=messages,
tools=fred.get_tool_definitions()
)
if response.choices[0].message.tool_calls:
tool_call = response.choices[0].message.tool_calls[0]
result = fred.execute_tool(
tool_call.function.name,
json.loads(tool_call.function.arguments)
)
messages.append(response.choices[0].message)
messages.append({
"role": "tool",
"content": json.dumps(result),
"tool_call_id": tool_call.id
})
final = client.chat.completions.create(model="gpt-4", messages=messages)
return final.choices[0].message.content
return response.choices[0].message.content
# Use it
answer = ask_fred("What's the GDP growth trend over the last 5 years?")
print(answer)
Popular Series IDs
GDP- Gross Domestic ProductUNRATE- Unemployment RateCPIAUCSL- Consumer Price Index (Inflation)FEDFUNDS- Federal Funds RateDGS10- 10-Year Treasury Constant Maturity RateSP500- S&P 500 Index
Environment Variables
Instead of passing api_key parameter, you can set:
export FRED_API_KEY="your-api-key-here"
Then use:
fred = FredTools() # Will use FRED_API_KEY from environment
Requirements
- Python 3.8+
httpx(installed automatically)
License
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
For commercial licensing options, please contact the maintainer.
Disclaimer
This open-source project is not affiliated with, sponsored by, or endorsed by the Federal Reserve or the Federal Reserve Bank of St. Louis. "FRED" is a registered trademark of the Federal Reserve Bank of St. Louis, used here for descriptive purposes only.
Credits
Converted from the excellent FRED MCP Server by Stefano Amorelli.
Links
- FRED Website: https://fred.stlouisfed.org/
- FRED API Docs: https://fred.stlouisfed.org/docs/api/
- Get API Key: https://fred.stlouisfed.org/docs/api/api_key.html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fred_toolkit-0.1.0.tar.gz.
File metadata
- Download URL: fred_toolkit-0.1.0.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
276879010f1a46e3566e3a4b15bf12ec74c434f9fd7ca15ce2b3be669f318b65
|
|
| MD5 |
4973c0262e160e6afd18cbdf05051433
|
|
| BLAKE2b-256 |
e945e27019bac26aaccd332e3745f7df1eee65b33be2e742afaf5bdaad2f1e4d
|
File details
Details for the file fred_toolkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fred_toolkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8b839211e56e779ecadf294e006e6169bd53fc9038cb115f7d412e6823b4a1e
|
|
| MD5 |
eb3c27b7a3d929abc05ab1eb5688170b
|
|
| BLAKE2b-256 |
2aa6a3bec4cbdd1f3dc86457b43dc8ee3da98fb0c2179411461e5b39d7c4d409
|