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.
pip install fredapiVerified import paths — ran on the pinned version, not inferred.
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.
Apply for a FRED API key at https://fred.stlouisfed.org/docs/api/api_key.html and configure it as an environment variable (`export FRED_API_KEY='your_key'`) or pass it directly: `fred = Fred(api_key='your_key')`.
Upgrade fredapi to version 0.5.1 or newer: `pip install --upgrade fredapi`. This version replaced `DataFrame.append` with `pd.concat`.
Upgrade fredapi to version 0.3.7 or newer: `pip install --upgrade fredapi`. This version switched to using HTTPS for all FRED API calls.
Install the 'fredapi' package using pip: `pip install fredapi` or using conda if in an Anaconda environment: `conda install -c conda-forge fredapi`.
Obtain a free API key from the FRED website (fred.stlouisfed.org) and provide it during Fred object initialization (e.g., `Fred(api_key='YOUR_API_KEY')`), set it as an environment variable `FRED_API_KEY`, or save it to a file specified by `api_key_file`.
Upgrade 'fredapi' to a version compatible with Python 3.9+ (e.g., `pip install --upgrade fredapi`) or ensure you are using a Python version older than 3.9.
Rename any local file named 'fredapi.py' to something else (e.g., 'my_fred_script.py') to avoid module shadowing, or ensure your import statement is `from fredapi import Fred` and not attempting to import a non-existent name.
Obtain a valid FRED API key from the FRED website (fred.stlouisfed.org/docs/api/api_key.html) and provide it when initializing Fred or set it as an environment variable: ```python # Option 1: Pass key directly from fredapi import Fred fred = Fred(api_key='YOUR_API_KEY') # Option 2: Set as environment variable (e.g., export FRED_API_KEY='YOUR_API_KEY' in your shell) # Then, fredapi will automatically pick it up: # from fredapi import Fred # fred = Fred() ```