Skip to content
Docs
Get API key

Get Started

Understand the Trading Economics API and start using it.

The Trading Economics Application Programming Interface (API) provides direct access to 300,000 economic indicators, exchange rates, stock market indexes, government bond yields, commodity prices, and company financials. You can also subscribe to quotes from our markets and streaming updates from our economic calendar and earnings releases calendar. We offer two distinct solutions that serve as convenient gateways to interact with our API: one in Python and the other in Node.js. However, you can interact with our API in different programming languages and we provide samples for some in our open source GitHub repository.

Authentication

To access the API, subscribe to a plan and get your API key at developer.tradingeconomics.com. You can pass the key as a c or client URL parameter, or using an Authorization HTTP header:

Python
import requests
your_api_key = 'your_api_key'
url = f'https://api.tradingeconomics.com/country/mexico?c={your_api_key}'
data = requests.get(url).json()
print(data)

The response data format can be configured by appending the &f= parameter to the URL request (supported formats: JSON or CSV)

Python
url = f'https://api.tradingeconomics.com/country/mexico?c={your_api_key}&f=csv'

You can use request headers to pass the API key:

Python
import requests

response = requests.get('https://api.tradingeconomics.com/country/mexico', headers = {'Authorization': 'your_api_key'})
print(response.json())

Packages

You can also use Trading Economics packages to have easy access to API. Below, we present a basic example to illustrate how to use these packages:

Pre-requirements

Install the tradingeconomics package using pip, a package management system used to install and manage software packages written in Python. In Windows Command Prompt or Linux bash type:

Python
pip install tradingeconomics

Using package

Python
import tradingeconomics as te                #1
te.login('your_api_key')                     #2
data = te.getIndicatorData(country='mexico') #3
  • #1 Imports Trading Economics Python package

  • #2 Calls the authentication method

  • #3 Makes a call to the API. You can change the parameters to what you like

By default, the response will be a list of dictionaries.

You can also change the output type to Pandas dataframe:

Python
data = te.getIndicatorData(country='mexico', output_type='df')

View on browser

Another alternative to visualize the data is using URLs. If you click at one of them, a new browser window will open with a data sample and the complete URL. To use them, just copy and paste in an internet browser or any other tool, changing the parameters to what you like.

You can visualize the response data in several formats by appending the &f= parameter to the URL request.

Text
https://api.tradingeconomics.com/country/{country}?c={your_api_key}&f=json
JSON
[
  {
    "Country": "Mexico",
    "Category": "Auto Exports",
    "Title": "Mexico Auto Exports",
    "LatestValueDate": "2023-08-31T00:00:00",
    "LatestValue": 287.85,
    "Source": "Instituto Nacional de Estadística y Geografía (INEGI)",
    "SourceURL": "https://www.inegi.org.mx/",
    "Unit": "Thousand Units",
    "URL": "/mexico/auto-exports",
    "CategoryGroup": "Trade",
    "Adjustment": "NSA",
    "Frequency": "Monthly",
    "HistoricalDataSymbol": "MEXICOAUTEXP",
    "CreateDate": "2019-07-23T12:20:00",
    "FirstValueDate": "1988-01-31T00:00:00",
    "PreviousValue": 275.77,
    "PreviousValueDate": "2023-07-31T00:00:00"
  },
  {
    "Country": "Mexico",
    "Category": "Balance of Trade",
    "Title": "Mexico Balance of Trade",
    "LatestValueDate": "2023-08-31T00:00:00",
    "LatestValue": -1377.09,
    "Source": "Instituto Nacional de Estadística y Geografía (INEGI)",
    "SourceURL": "https://www.inegi.org.mx/",
    "Unit": "USD Million",
    "URL": "/mexico/balance-of-trade",
    "CategoryGroup": "Trade",
    "Adjustment": "NSA",
    "Frequency": "Monthly",
    "HistoricalDataSymbol": "MXTBBAL",
    "CreateDate": "2014-07-25T14:01:00",
    "FirstValueDate": "1980-01-31T00:00:00",
    "PreviousValue": -881.2,
    "PreviousValueDate": "2023-07-31T00:00:00"
  },
  {
    "Country": "Mexico",
    "Category": "Banks Balance Sheet",
    "Title": "Mexico Banks Balance Sheet",
    "LatestValueDate": "2023-08-31T00:00:00",
    "LatestValue": 10702998.84,
    "Source": "Banco de México",
    "SourceURL": "http://www.banxico.org.mx",
    "Unit": "MXN Million",
    "URL": "/mexico/banks-balance-sheet",
    "CategoryGroup": "Money",
    "Adjustment": "NSA",
    "Frequency": "Monthly",
    "HistoricalDataSymbol": "MEXICOBANBALSHE",
    "CreateDate": "2014-09-08T15:29:00",
    "FirstValueDate": "2000-12-31T00:00:00",
    "PreviousValue": 10608854.67,
    "PreviousValueDate": "2023-07-31T00:00:00"
  }
]

GitHub

You can look for other examples on how to use our API in different programming languages, in our GitHub repository.

Authentication Details of API Authentication Installation Details of API Installation Usage Reports Monitor your API usage, understand rate limits and response status codes. Rate Limits Details of API usage limits and request quotas. Response Status List of API response status codes and their meanings.