How tradingeconomics/tradingeconomics-python works
Purpose and package entry point
tradingeconomics is a Python client SDK for the Trading Economics API: economic indicators, calendar events, market data, forecasts, news, and historical datasets. Consumers import the package and authenticate/call its top-level API, centered on tradingeconomics/__init__.py; packaging is defined by setup.py and tradingeconomics/requirements.txt.
Authentication and shared client state
Authentication is initiated through te.login() and likely configures shared API credentials/state used by all endpoint modules. Environment-supplied apikey is the intended credential boundary; API access requires a Trading Economics subscription. Shared request and utility behavior is concentrated in:
• tradingeconomics/__init__.py
• tradingeconomics/glob.py
• tradingeconomics/functions.py
Domain endpoint façade
The SDK exposes domain-specific, function-oriented modules rather than a server application. Each module maps user parameters into Trading Economics API requests and returns API results, including optional DataFrame-oriented output where supported. Primary domains include:
• Calendar and indicators: tradingeconomics/calendar.py, tradingeconomics/indicators.py, tradingeconomics/forecasts.py
• Markets and corporate data: tradingeconomics/markets.py, tradingeconomics/financials.py, tradingeconomics/earnings.py
• Content and discovery: tradingeconomics/news.py, tradingeconomics/search.py
• Public-data source integrations: tradingeconomics/worldBank.py, tradingeconomics/eurostat.py, tradingeconomics/comtrade.py, tradingeconomics/federalReserve.py
Historical-data access layer
Historical retrieval is split by source/data model rather than folded into live endpoint modules. This creates distinct request semantics for generic series, database-backed datasets, and specialized financial/market/Eurostat history:
• tradingeconomics/historical.py
• tradingeconomics/historicalDB.py
• tradingeconomics/historicalMarkets.py
• tradingeconomics/historicalFinancials.py
• tradingeconomics/historicalEurostat.py
Streaming control path
Real-time subscriptions are a separate lifecycle from request/response API calls. The streaming client is responsible for URL construction and connection callbacks/errors, allowing calendar, markets, or news updates to be consumed continuously:
• tradingeconomics/stream.py
• examples/stream-python/app.py
• examples/calendar/calendarStreamingEx.py
Consumer-facing execution surfaces
The installed Python package is the main runtime. Examples demonstrate direct scripts, CSV-producing workflows, and lightweight interactive applications; these are consumers of the SDK rather than core service layers:
• examples/Indicators/indicatorsEx.py
• examples/historical/historicalChart.py
• examples/calendar/calendarApp.py
• examples/forecasts/forecastsApp.py
Runtime, external boundary, and delivery
The material external dependency is the authenticated Trading Economics API and its real-time update service. The package runs in Python, is distributable through PyPI, and can run in Docker:
• Dockerfile
• setup.py
• .github/workflows/python-publish.yml
• .github/workflows/integration-tests.yml
The principal flow is: application imports tradingeconomics → calls login to establish credentials → invokes a domain or historical façade → shared functions construct/send authenticated API requests → results return to the caller; streaming instead maintains a callback-driven subscription connection.
Main entry points: __init__.py Package entry point · functions.py Request utilities · stream.py Streaming client · glob.py Shared client state
Components 18
Python SDK
Installed client package.
- Package entry point · Exports the top-level client API including login.
tradingeconomics/__init__.py - Shared client state · Holds API credential and shared client settings.
tradingeconomics/glob.py - Request utilities · Builds and sends authenticated API requests.
tradingeconomics/functions.py - Economic endpoints · Calendar, indicators, and forecasts requests.
tradingeconomics/calendar.py - Markets endpoints · Markets, financials, and earnings requests.
tradingeconomics/markets.py - Content endpoints · News and search requests.
tradingeconomics/news.py - Public-source endpoints · World Bank, Eurostat, Comtrade, and Federal Reserve integrations.
tradingeconomics/worldBank.py - Historical access · Generic, database, market, financial, and Eurostat history retrieval.
tradingeconomics/historical.py - Streaming client · Manages subscription URLs, callbacks, and connection errors.
tradingeconomics/stream.py
Consumer surfaces
Example scripts and applications use the SDK.
- Examples and apps · Scripts, charts, CSV workflows, and interactive applications.
examples/Indicators/indicatorsEx.py - Streaming examples · Demonstrate callback-driven subscriptions.
examples/stream-python/app.py
Delivery
Package publishing and container execution.
- Package build · Defines installable package metadata and dependencies.
setup.py - Docker runtime · Runs the SDK environment in a container.
Dockerfile - Publish workflow · Publishes package releases.
.github/workflows/python-publish.yml - Integration workflow · Runs API integration validation.
.github/workflows/integration-tests.yml
Other components
- Environment API key · Subscription credential supplied by the consumer environment.
- Trading Economics API · Authenticated request-response data service.
- Real-time update service · Continuous calendar, market, and news updates.
Connections 24
- Examples and apps → Package entry point: imports and calls
- Streaming examples → Package entry point: authenticates through
- Streaming examples → Streaming client: subscribes with
- Environment API key → Package entry point: supplies credential
- Package entry point → Shared client state: login configures
- Package entry point → Economic endpoints: exposes
- Package entry point → Markets endpoints: exposes
- Package entry point → Content endpoints: exposes
- Package entry point → Public-source endpoints: exposes
- Package entry point → Historical access: exposes
- Package entry point → Streaming client: exposes
- Shared client state → Request utilities: provides credentials
- Economic endpoints → Request utilities: uses
- Markets endpoints → Request utilities: uses
- Content endpoints → Request utilities: uses
- Public-source endpoints → Request utilities: uses
- Historical access → Request utilities: uses
- Request utilities → Trading Economics API: authenticated requests
- Streaming client → Shared client state: uses credentials
- Streaming client → Real-time update service: maintains subscription
- Package build → Package entry point: packages
- Publish workflow → Package build: publishes
- Integration workflow → Package entry point: validates
- Docker runtime → Package entry point: runs