SDKs overview

Software Development Kits (SDKs) and libraries for FRED facilitate programmatic access to the Federal Reserve Economic Data (FRED) API. These tools abstract the underlying HTTP requests and JSON parsing, allowing developers and researchers to focus on data utilization rather than API mechanics. The FRED API provides access to over 800,000 U.S. and international economic time series from more than 100 sources, maintained by the Federal Reserve Bank of St. Louis (FRED API documentation).

FRED offers official SDKs for Python and R, which are widely used in data science, econometrics, and financial analysis. These SDKs are designed to integrate seamlessly with their respective language ecosystems, providing idiomatic ways to fetch, process, and analyze economic data. Community-contributed libraries also exist, extending functionality or offering alternative approaches to FRED data interaction.

Using an SDK can significantly reduce development time by handling tasks such as API key management, request construction, error handling, and data deserialization. This enables users to quickly retrieve specific economic indicators, series observations, releases, and categories directly within their preferred programming environment.

Official SDKs by language

The Federal Reserve Bank of St. Louis provides official client libraries for Python and R, which are the primary languages supported for interacting with the FRED API. These libraries are maintained to ensure compatibility with the latest API versions and offer comprehensive functionality for accessing the full range of FRED data.

Language Package Name Install Command (Example) Maturity
Python fredapi pip install fredapi Stable, actively maintained
R fredr install.packages("fredr") Stable, actively maintained

Both the fredapi for Python and fredr for R are designed to mirror the structure and capabilities of the FRED API, providing functions for searching series, retrieving observations, managing release data, and exploring categories. They typically require an API key, which can be obtained free of charge from the FRED website (FRED API Key Request).

Installation

Installation of FRED's official SDKs is straightforward, utilizing the standard package managers for Python and R environments. Prior to installation, users should ensure they have the respective language environment set up on their system.

Python (fredapi)

To install the fredapi library for Python, use pip, the Python package installer. It is recommended to use a virtual environment to manage dependencies.

pip install fredapi

After installation, you will need to set up your FRED API key. This can be done by passing the key directly to the Fred object constructor or by storing it in a configuration file or environment variable for persistent use (fredapi documentation).

R (fredr)

To install the fredr library for R, use the install.packages() function within your R console.

install.packages("fredr")

Similar to Python, the fredr package requires an API key. This can be set globally using fredr_set_key() or passed to individual function calls. It is often recommended to store the API key as an environment variable for security and convenience (fredr package documentation).

Quickstart example

The following examples demonstrate how to retrieve the Gross Domestic Product (GDP) series using both the Python and R SDKs. These snippets illustrate basic authentication and data retrieval for a common economic indicator.

Python Quickstart

This Python example uses the fredapi library to fetch the latest observations for the 'GDP' series.

from fredapi import Fred
import os

# Replace 'YOUR_FRED_API_KEY' with your actual API key
# It's recommended to store API keys as environment variables
# fred = Fred(api_key=os.environ.get('FRED_API_KEY'))
fred = Fred(api_key='YOUR_FRED_API_KEY')

# Get the latest observations for the 'GDP' series
data = fred.get_series('GDP')

print("Latest GDP observations:")
print(data.tail())

This code initializes the Fred client with an API key and then calls get_series() to retrieve the data. The .tail() method is used to display the most recent entries.

R Quickstart

This R example uses the fredr library to retrieve the latest observations for the 'GDP' series.

# Install and load the fredr package if you haven't already
# install.packages("fredr")
library(fredr)

# Replace 'YOUR_FRED_API_KEY' with your actual API key
# It's recommended to set the API key as an environment variable
# Sys.setenv(FRED_API_KEY = "YOUR_FRED_API_KEY")
fredr_set_key("YOUR_FRED_API_KEY")

# Get the latest observations for the 'GDP' series
data <- fredr_series_observations(series_id = "GDP")

cat("Latest GDP observations:\n")
print(tail(data))

This R code sets the API key and then uses fredr_series_observations() to fetch the data. The tail() function displays the most recent data points.

Community libraries

While FRED provides official SDKs, the open-source community often develops additional libraries that can complement or extend the functionality. These libraries may offer specialized data handling, integration with other tools, or alternative interfaces. Users should evaluate community libraries for their maintenance status, documentation, and specific features before incorporating them into critical applications.

For example, in the Python ecosystem, libraries like pandas-datareader, while not solely dedicated to FRED, often include FRED as one of its data sources. This allows for a unified interface to fetch data from multiple financial and economic sources, including FRED, directly into pandas DataFrames (pandas-datareader documentation). Such libraries can be particularly useful for researchers who work with data from various providers.

Another example of a community-driven approach to economic data access is seen in the broader data science community, where tools like Jupyter notebooks and R Markdown are frequently used alongside FRED SDKs to create reproducible research workflows (Google Earth Engine Jupyter Guide). These environments facilitate the integration of data retrieval, analysis, and visualization, often leveraging the official FRED SDKs within their frameworks.

When considering community-contributed libraries, it is advisable to check their GitHub repositories or official documentation for activity, issue resolution, and compatibility with the latest FRED API specifications. This ensures that the chosen library remains functional and secure over time.