# Get Started

> Understand the Trading Economics API and start using it.

Source: https://docs.tradingeconomics.com/get_started/

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](https://github.com/tradingeconomics/tradingeconomics).

## Authentication
To access the API, [subscribe to a plan](https://tradingeconomics.com/analytics/pricing.aspx) and get your API key at [developer.tradingeconomics.com](https://developer.tradingeconomics.com/). You can pass the key as a **c** or **client** URL parameter, or using an **Authorization** HTTP header:

**PYTHON**
```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())
```

**JS**
```js
const axios = require('axios');
(async () => {    
    const your_api_key = 'your_api_key'
    const response = await axios.get(`https://api.tradingeconomics.com/country/mexico?c=${your_api_key}`)
    console.log(response.data)
})()
```

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

```javascript
const response = await axios.get(`https://api.tradingeconomics.com/country/mexico?c=${your_api_key}&f=csv`)
```

You can use **request headers** to pass the API key:
```javascript
(async () => {
  const url = 'https://api.tradingeconomics.com/country/mexico';
  const headers = { 'Authorization': 'your_api_key' };

  try {
    const response = await fetch(url, { method: 'GET', headers });
    const data = await response.text();
    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();
```

**C#**
To use Trading Economics API with any server based language, copy and paste an endpoint and change its parameters to what you like.

By default, Server based languages show data as string: 

```c#
using (var httpClient = new HttpClient())
{
    using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?c=your_api_key"))
    {
        request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");
        var response = await httpClient.SendAsync(request);
        if (response.IsSuccessStatusCode)
        {
            var content = await response.Content.ReadAsStringAsync(); 
            Console.WriteLine(content);
        }
    }
}
```

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

```c#
new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?c=your_api_key&f=csv")
```

## 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:

**PYTHON**
**Pre-requirements**

* Recent version of [Python](https://www.python.org/downloads/).
  
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')
```

**JS**
**Pre-requirements**

* Recent [Node.js](https://nodejs.org/en) version.

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

```javascript
npm install tradingeconomics
```
**Using package**
```javascript
const te = require('tradingeconomics');                              //1
te.login('your_api_key');                                            //2
data = te.getIndicatorData(country = 'mexico').then(function(data){  //3
});
```

* //1 Imports Trading Economics Node.js package

* //2 Calls the authentication method

* //3 Makes a call to the API. You can change the parameters to what you like

By default, Node.js package shows data as array of Javascript objects.

## 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.

**JSON**
```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"
  }
]
```

**CSV**
```text
https://api.tradingeconomics.com/country/{country}?c={your_api_key}&f=csv
```
```bash
Country,Category,Title,LatestValueDate,LatestValue,Source,SourceURL,Unit,URL,CategoryGroup,Adjustment,Frequency,HistoricalDataSymbol,CreateDate,FirstValueDate,PreviousValue,PreviousValueDate
Mexico,Auto Exports,Mexico Auto Exports,8/31/2023 12:00:00 AM,287.85,Instituto Nacional de Estadística y Geografía (INEGI),https://www.inegi.org.mx/,Thousand Units,/mexico/auto-exports,Trade,NSA,Monthly,MEXICOAUTEXP,7/23/2019 12:20:00 PM,1/31/1988 12:00:00 AM,275.77,7/31/2023 12:00:00 AM
Mexico,Balance of Trade,Mexico Balance of Trade,8/31/2023 12:00:00 AM,-1377.09,Instituto Nacional de Estadística y Geografía (INEGI),https://www.inegi.org.mx/,USD Million,/mexico/balance-of-trade,Trade,NSA,Monthly,MXTBBAL,7/25/2014 2:01:00 PM,1/31/1980 12:00:00 AM,-881.20,7/31/2023 12:00:00 AM
Mexico,Banks Balance Sheet,Mexico Banks Balance Sheet,8/31/2023 12:00:00 AM,10702998.84,Banco de México,http://www.banxico.org.mx,MXN Million,/mexico/banks-balance-sheet,Money,NSA,Monthly,MEXICOBANBALSHE,9/8/2014 3:29:00 PM,12/31/2000 12:00:00 AM,10608854.67,7/31/2023 12:00:00 AM
```

**HTML**
```text
https://api.tradingeconomics.com/country/{country}?c={your_api_key}
```

| Country | Category | Title | LatestValueDate | LatestValue | Source | SourceURL | Unit | URL | CategoryGroup | Adjustment | Frequency | HistoricalDataSymbol | CreateDate | FirstValueDate | PreviousValue | PreviousValueDate |
|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|
| Mexico | Auto Exports | Mexico Auto Exports | 6/30/2023 12:00:00 AM | 286.29 | Instituto Nacional de Estadística y Geografía (INEGI) | https://www.inegi.org.mx/ | Thousand Units | /mexico/auto-exports | Trade | NSA | Monthly | MEXICOAUTEXP | 7/23/2019 12:20:00 PM | 1/31/1988 12:00:00 AM | 279.27 | 5/31/2023 12:00:00 AM |
| Mexico | Balance of Trade| Mexico Balance of Trade | 5/31/2023 12:00:00 AM | -74.00 | Instituto Nacional de Estadística y Geografía (INEGI) | https://www.inegi.org.mx/ | USD Million | /mexico/balance-of-trade | Trade | NSA | Monthly | MXTBBAL | 7/25/2014 2:01:00 PM | 1/31/1980 12:00:00 AM | -1509.00 | 4/30/2023 12:00:00 AM |
| Mexico | Banks Balance Sheet | Mexico Banks Balance Sheet | 4/30/2023 12:00:00 AM | 10335903.02 | Banco de México | https://www.banxico.org.mx | MXN Million | /mexico/banks-balance-sheet | Trade | NSA | Monthly | MEXICOBANBALSHE | 9/8/2014 3:29:00 PM | 12/31/2000 12:00:00 AM | 10169075.64 | 3/31/2023 12:00:00 AM |

## GitHub

You can look for other examples on how to use our API in different programming languages, in our [GitHub](https://github.com/tradingeconomics/tradingeconomics) repository.


## Pages in this section

- [Trading Economics API Authentication](https://docs.tradingeconomics.com/get_started/authentication/index.md): Details of API Authentication
- [Trading Economics | Packages Installation](https://docs.tradingeconomics.com/get_started/installation/index.md): Details of API Installation
- [TRADING ECONOMICS - API Usage Reports](https://docs.tradingeconomics.com/get_started/reports/index.md): Monitor your API usage, understand rate limits and response status codes.
- [API Rate Limits](https://docs.tradingeconomics.com/get_started/rate-limits/index.md): Details of API usage limits and request quotas.
- [API Response Status Codes](https://docs.tradingeconomics.com/get_started/response-status/index.md): List of API response status codes and their meanings.

