# tradingeconomics/tradingeconomics-python architecture

> Architecture diagram of the GitHub repository tradingeconomics/tradingeconomics-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tradingeconomics/tradingeconomics-python
- Repository: https://github.com/tradingeconomics/tradingeconomics-python

## Overview

#### 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: [`tradingeconomics/__init__.py`](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/__init__.py) (Package entry point), [`tradingeconomics/functions.py`](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/functions.py) (Request utilities), [`tradingeconomics/stream.py`](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/stream.py) (Streaming client), [`tradingeconomics/glob.py`](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/glob.py) (Shared client state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sdk["Python SDK"]
  node_package["Package entry point<br/>Python API<br/>[__init__.py]"]
  node_state["Shared client state<br/>credentials<br/>[glob.py]"]
  node_request_utils["Request utilities<br/>HTTP client<br/>[functions.py]"]
  node_economic["Economic endpoints<br/>domain façade<br/>[calendar.py]"]
  node_markets["Markets endpoints<br/>domain façade<br/>[markets.py]"]
  node_content["Content endpoints<br/>domain façade<br/>[news.py]"]
  node_public_sources["Public-source endpoints<br/>domain façade<br/>[worldBank.py]"]
  node_history["Historical access<br/>data façade<br/>[historical.py]"]
  node_stream["Streaming client<br/>subscription client<br/>[stream.py]"]
end

subgraph group_consumers["Consumer surfaces"]
  node_examples["Examples and apps<br/>Python consumers<br/>[indicatorsEx.py]"]
  node_stream_example["Streaming examples<br/>Python consumers<br/>[app.py]"]
end

subgraph group_delivery["Delivery"]
  node_package_build["Package build<br/>PyPI distribution<br/>[setup.py]"]
  node_docker["Docker runtime<br/>container"]
  node_publish["Publish workflow<br/>CI workflow<br/>[python-publish.yml]"]
  node_integration["Integration workflow<br/>CI workflow"]
end

node_api_key{{"Environment API key<br/>credential boundary"}}
node_api{{"Trading Economics API<br/>external API"}}
node_realtime{{"Real-time update service<br/>external stream"}}

node_examples -->|"imports and calls"| node_package
node_stream_example -->|"authenticates through"| node_package
node_stream_example -->|"subscribes with"| node_stream
node_api_key -->|"supplies credential"| node_package
node_package -->|"login configures"| node_state
node_package -->|"exposes"| node_economic
node_package -->|"exposes"| node_markets
node_package -->|"exposes"| node_content
node_package -->|"exposes"| node_public_sources
node_package -->|"exposes"| node_history
node_package -->|"exposes"| node_stream
node_state -->|"provides credentials"| node_request_utils
node_economic -->|"uses"| node_request_utils
node_markets -->|"uses"| node_request_utils
node_content -->|"uses"| node_request_utils
node_public_sources -->|"uses"| node_request_utils
node_history -->|"uses"| node_request_utils
node_request_utils -->|"authenticated requests"| node_api
node_stream -->|"uses credentials"| node_state
node_stream -->|"maintains subscription"| node_realtime
node_package_build -->|"packages"| node_package
node_publish -->|"publishes"| node_package_build
node_integration -.->|"validates"| node_package
node_docker -->|"runs"| node_package

click node_package "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/__init__.py"
click node_state "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/glob.py"
click node_request_utils "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/functions.py"
click node_economic "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/calendar.py"
click node_markets "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/markets.py"
click node_content "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/news.py"
click node_public_sources "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/worldBank.py"
click node_history "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/historical.py"
click node_stream "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/stream.py"
click node_examples "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/examples/Indicators/indicatorsEx.py"
click node_stream_example "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/examples/stream-python/app.py"
click node_package_build "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/setup.py"
click node_docker "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/Dockerfile"
click node_publish "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/.github/workflows/python-publish.yml"
click node_integration "https://github.com/tradingeconomics/tradingeconomics-python/blob/main/.github/workflows/integration-tests.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package,node_state,node_request_utils,node_economic,node_markets,node_content,node_public_sources,node_history,node_stream toneBlue
class node_examples,node_stream_example toneAmber
class node_package_build,node_docker,node_publish,node_integration toneMint
class node_api_key,node_api,node_realtime toneNeutral
```

## Components

### Python SDK

Installed client package.

- [Package entry point](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/__init__.py): Python API · Exports the top-level client API including login. · `tradingeconomics/__init__.py`
- [Shared client state](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/glob.py): credentials · Holds API credential and shared client settings. · `tradingeconomics/glob.py`
- [Request utilities](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/functions.py): HTTP client · Builds and sends authenticated API requests. · `tradingeconomics/functions.py`
- [Economic endpoints](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/calendar.py): domain façade · Calendar, indicators, and forecasts requests. · `tradingeconomics/calendar.py`
- [Markets endpoints](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/markets.py): domain façade · Markets, financials, and earnings requests. · `tradingeconomics/markets.py`
- [Content endpoints](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/news.py): domain façade · News and search requests. · `tradingeconomics/news.py`
- [Public-source endpoints](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/worldBank.py): domain façade · World Bank, Eurostat, Comtrade, and Federal Reserve integrations. · `tradingeconomics/worldBank.py`
- [Historical access](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/historical.py): data façade · Generic, database, market, financial, and Eurostat history retrieval. · `tradingeconomics/historical.py`
- [Streaming client](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/tradingeconomics/stream.py): subscription client · Manages subscription URLs, callbacks, and connection errors. · `tradingeconomics/stream.py`

### Consumer surfaces

Example scripts and applications use the SDK.

- [Examples and apps](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/examples/Indicators/indicatorsEx.py): Python consumers · Scripts, charts, CSV workflows, and interactive applications. · `examples/Indicators/indicatorsEx.py`
- [Streaming examples](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/examples/stream-python/app.py): Python consumers · Demonstrate callback-driven subscriptions. · `examples/stream-python/app.py`

### Delivery

Package publishing and container execution.

- [Package build](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/setup.py): PyPI distribution · Defines installable package metadata and dependencies. · `setup.py`
- [Docker runtime](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/Dockerfile): container · Runs the SDK environment in a container. · `Dockerfile`
- [Publish workflow](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/.github/workflows/python-publish.yml): CI workflow · Publishes package releases. · `.github/workflows/python-publish.yml`
- [Integration workflow](https://github.com/tradingeconomics/tradingeconomics-python/blob/main/.github/workflows/integration-tests.yml): CI workflow · Runs API integration validation. · `.github/workflows/integration-tests.yml`

### Other components

- **Environment API key**: credential boundary · Subscription credential supplied by the consumer environment.
- **Trading Economics API**: external API · Authenticated request-response data service.
- **Real-time update service**: external stream · Continuous calendar, market, and news updates.

## Connections

- 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
