Trading Economics API
raw JSON → 4.5.9 verified Mon Apr 27 auth: no python
Python wrapper for the Trading Economics API, providing access to economic indicators, calendar events, commodities, currencies, bonds, and forecasts. Current version 4.5.9. Active development with irregular releases.
pip install tradingeconomics Common errors
error tradingeconomics.exceptions.AuthenticationError: Authentication failed ↓
cause Invalid API key or missing login call before data request.
fix
Ensure te.login('YOUR_API_KEY') is called and key is correct.
error AttributeError: module 'tradingeconomics' has no attribute 'getIndicatorData' ↓
cause Using version 3.x style direct function calls; version 4.x uses module-level functions.
fix
Update imports: use import tradingeconomics as te, then te.getIndicatorData().
error TypeError: login() takes 0 positional arguments but 1 was given ↓
cause Version 4.5.9 requires keyword argument: te.login(api_key='YOUR_KEY') or positional in older versions.
fix
Use te.login('YOUR_API_KEY') or te.login(api_key='YOUR_API_KEY') depending on version. Check docs.
Warnings
breaking Version 4.x removed direct function access; all endpoints are now methods under the tradingeconomics module (e.g., te.getIndicatorData instead of standalone getIndicatorData). Rewrite imports and calls. ↓
fix Use module-level functions: import tradingeconomics as te then te.login() and te.getIndicatorData()
gotcha The login() function must be called before any data fetch. Missing leads to AuthenticationError. ↓
fix Always call te.login('YOUR_API_KEY') first.
deprecated getCalendar() returns raw JSON; consider using getCalendarData() with filters for structured responses. ↓
fix Use getCalendarData() instead of getCalendar() for filtered results.
Imports
- tradingeconomics
import tradingeconomics as te - te.login() wrong
te.login('key')correctte.login('YOUR_KEY')
Quickstart
import tradingeconomics as te
te.login(os.environ.get('TE_API_KEY', ''))
data = te.getIndicatorData(country='United States', indicator='GDP')
print(data)