__init__#

FredAPI.__init__(api_key=None, cache_mode=False, cache_size=256)[source]#

Initialize the FredAPI class that provides functions which query FRED data.

Parameters:
  • api_key (Optional[str]) – Your FRED API key.

  • cache_mode (bool, optional) – Whether to enable caching for API responses. Defaults to False.

  • cache_size (int, optional) – The maximum number of items to store in the cache if caching is enabled. Defaults to 256.

Returns:

An instance of the FredAPI class.

Return type:

FredAPI

Raises:

RuntimeError – If no API key can be resolved from the explicit argument, global setting, or environment variable.

Example

>>> import fedfred as fd
>>> fd.set_api_key("your_api_key")  # optional global
>>> fred = fd.FredAPI()             # uses global/env key

Or explicitly:

>>> fred = fd.FredAPI(api_key="your_api_key")