Consumer Price Index
Consumer Price Index (CPI) is a measure that examines the average change in prices paid by consumers for goods and services over time. It is a measure of inflation.
By default, data comes from the Global Macro Database (GMDB), which is annual-only (base year 2010). Set oecd_source=True to instead retrieve monthly or quarterly data from the OECD (base year varies per country), useful for tracking inflation more closely in real time.
Data comes from the Global Macro Database (GMDB), further information about the variable can be found within https://www.globalmacrodata.com/documentation.html
Also known as: CPI, cost of living index.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Consumer Price Index for you. Just ask in plain English.
Calculate the Consumer Price Index in Python
The Consumer Price Index is available in the Economics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_consumer_price_index as shown below.
from financetoolkit import Economics
economics = Economics(start_date='2008-09-01', end_date='2020-03-01')
economics.get_consumer_price_index(countries=['Germany', 'France', 'Portugal'])
Which returns:
| Germany | France | Portugal | |
|---|---|---|---|
| 2008 | 98.6508 | 98.1924 | 99.527 |
| 2009 | 98.8937 | 98.2913 | 98.628 |
| 2010 | 100 | 100 | 100 |
| 2011 | 102.482 | 102.287 | 103.555 |
| 2012 | 104.695 | 104.553 | 106.43 |
| 2013 | 106.377 | 105.589 | 106.897 |
| 2014 | 107.196 | 106.236 | 106.727 |
| 2015 | 107.924 | 106.328 | 107.269 |
| 2016 | 108.32 | 106.653 | 107.951 |
| 2017 | 110.164 | 107.896 | 109.631 |
| 2018 | 112.296 | 110.162 | 110.91 |
| 2019 | 113.815 | 111.591 | 111.243 |
| 2020 | 114.239 | 112.18 | 111.108 |
Parameters
get_consumer_price_index accepts the following parameters:
- countries (list[str] | str | None, optional): The countries to include in the data. Defaults to None.
- period (str | None, optional): Whether to return the monthly, quarterly or the annual data.
Only used when
oecd_source=True; the GMDB source is always annual. Defaults to None. - oecd_source (bool, optional): Whether to get the data from the OECD instead of the Global Macro Database (GMDB). Defaults to False.
- rolling (int, optional): The rolling window size to use for smoothing the data (simple moving average). Defaults to None.
- trailing (int, optional): The trailing window size to use for summing the data over trailing periods (e.g. a trailing-4-quarter sum). Defaults to None.
- growth (bool, optional): Whether to return the growth data or the actual data.
- lag (int, optional): The number of periods to lag the data by.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Related Economy
The Economics module page introduces the module, and the sidebar lists all of its functions.