cpi
raw JSON → 2.0.10 verified Fri May 01 auth: no python
Quickly adjust U.S. dollars for inflation using the Consumer Price Index (CPI). Uses FRED data. Current version 2.0.10, actively maintained with regular data updates.
pip install cpi Common errors
error ModuleNotFoundError: No module named 'cpi' ↓
cause Library not installed or installed in wrong Python environment.
fix
Run 'pip install cpi' or verify environment.
error cpi.exceptions.CPINotFoundError: No CPI data found for 1990 ↓
cause Year outside available data range (usually 1913 onward).
fix
Check that the input year is >= 1913 and <= current year+1.
error AttributeError: module 'cpi' has no attribute 'to_usd' ↓
cause Old import style used with newer version where function removed or renamed.
fix
Use 'from cpi import adjust' instead of 'import cpi; cpi.to_usd()'.
Warnings
deprecated cpi.to_usd() is deprecated in favor of adjust() ↓
fix Use from cpi import adjust; adjust(100, 1990, 2023)
gotcha Year ranges are inclusive for the start year; end year is exclusive (i.e., data up to but not including end year). ↓
fix To adjust from 2020 to 2023, use to_usd(amount, 2020, 2023). It uses CPI data through 2022.
gotcha First run downloads CPI data from FRED; requires internet. Subsequent runs use a local cache. ↓
fix Ensure internet access on first use. Cache location: ~/.cpi/ on Linux/macOS.
Imports
- cpi.to_usd wrong
import cpi; cpi.to_usd()correctfrom cpi import to_usd - adjust wrong
import cpi; cpi.adjust()correctfrom cpi import adjust
Quickstart
from cpi import to_usd
print(to_usd(100, 1990, 2023))