pyfredapi
pyfredapi is a Python library that makes it is easy to retrieve data from the FRED API web service.
pyfredapi covers all the FRED API endpoints, and can retrieve data from FRED and ALFRED.
Data can be returned as a pandas dataframe or as json. Requests to the FRED API can be customized according to
the parameters made available by the web service endpoints.
Installation
pyfredapi can be installed via pip.
pip install pyfredapi
# install with plotting dependencies
pip install 'pyfredapi[plot]'
FRED API Key
Before you can use pyfredapi you must have an API key to the FRED API web service. You can apply for one for free on the FRED website.
You can set your API key in two ways:
- set your API key to the environment variable :code:
FRED_API_KEY - pass it to the :code:
api_keyparameter of the request function
You can set the API key as an environment variable by adding the following line to your ~/.zshrc, ~/.bashrc file:
export FRED_API_KEY="your_api_key"
Quick Start
Each of the FRED API endpoint namespaces is covered by a module in pyfredapi. For a deeper dive into each of the
modules see the tutorials and API documentation in the sidebar.
category- covers the FRED Categories endpointsmaps- covers the FRED Maps endpointsrelease- covers the FRED Releases endpointsseries- covers the FRED Series endpointssources- covers the FRED Sources endpointstags- covers the FRED Tags endpointsseries_collection- makes handling multiple series easier
Quick start example:
import pyfreadpi as pf
# api key set as environment variable
pf.get_series_info(series_id="GDP")
# api key passed to function
pf.get_series_info(series_id="GDP", api_key="my_api_key")