February 4, 2020

Get High-Quality Financial Data Directly into Python

Now you’re two code lines away from gaining real-time access to world financial exchanges. This tutorial will show you how to install the Python library and use its main features.
  • Production ready. Data available in pandas, json and csv formats.
  • Technical analysis. About 100 available and ready-for-use technical indicators.
  • Unique experiences. Static and interactive charts from the same source as financial data.
  • Any complexity. Many subsidiary methods to build from simple applications to ML & AI projects.
This library is absolutely free to use and immediately provides access to all methods. You will also need a personal API Key.
Apple Inc. stock, with MACD, EMA and ADX indicators converted to pandas
Apple Inc. stock with MACD, EMA and ADX indicators converted to pandas


Download module from PyPi
pip install twelvedata
If you need additional modules, e.g., for charting - list them in square brackets
pip install twelvedata[matplotlib,plotly]


The base object for all method calls is TDClient. We can define this only once at the beginning and use it throughout the whole application.
    from twelvedata import TDClient
td = TDClient(apikey="your_api_key")  
Access Time Series
We get time-series data by calling the appropriate object. Pass necessary parameters and use it as a template for future calls, without the necessity of defining it again, unless some parameters have to be modified.
    ts = td.time_series(
Access Technical Indicators
All technical indicators are called on top of time_series(...) object, following .with_{technical_indicator_name} format. Custom parameters may be passed, if not - defaults are taken.
Full list of technical indicators and it's parameters is available at TI Documentation or at get_technical_indicators_list() endpoint.

Format Control

Returns pandas.core.frame.DataFrame object which can be used for Machine Learning and other programs that require extensive data manipulation.
Is the most popular choice for the majority of applications with non-complex data usage.
Suits programs that need to easily convert data to human-readable format.
Returns matplotlib.figure.Figure object which might be rendered as ready static chart.
Returns plotly.graph_objs._figure.Figure object which might be rendered as ready interactive chart.

Dates Control

Custom dates and output size parameters might be passed to time series object.
To select the most recent 25 data points, use outputsize parameter.
    ts = td.time_series(
To select all data between 2020-01-01 and 2020-02-01, we set date parameters.
    ts = td.time_series(
Both outputsize and dates parameters may also be used simultaneously.

Advanced Control

In order to get DateTime value in a convenient form, the timezone parameter might be specified.
    ts = td.time_series(
Stocks also accept exchange and country parameters, while cryptocurrencies support only exchange.
    ts = td.time_series(
For other acceptable parameters you may refer to API Documentation

Reference Data

Reference Data endpoints are called directly from TDClient object. Majority of them might be converted either to .as_json() or .as_csv() formats.
    # Stocks List in CSV format
# Stock Exchanges List
# Forex Pairs List
# Cryptocurrencies List
# Cryptocurrency Exchanges List
# Technical Indicators Interface is only available in JSON
Source code is available at GitHub repository.

Share article

More articles

August 10, 2021

API3 Alliance Officially Announced with Twelve Data as a Founding Member

Twelve Data, a Founding Member of the API3 Alliance, To Offer First-Party Oracle Services on Web3 Leading Web API provider to provide data and services to the next generation of decentralized applications via Airnode Singapore – August 10, 2021 — Twelve Data today joined with [API3](https://api3.

August 7, 2021

Twelve Data Google Sheets Add-on Documentation

This guide will make sure to highlight all the features available with the Twelve Data Google Sheets Add-on.

August 7, 2021

Twelve Data Google Sheets Add-on Installation Guide

There are two methods to install this add-on: for yourself or for the entire domain (G Suite).

July 30, 2021

Twelve Data Launches Chainlink Node, Bringing Non-U.S. Equities, ETF, and Index Prices to DeFi

[Twelve Data](https://twelvedata.

January 11, 2021

Twelve Data to Launch Chainlink Oracle Node, Providing Origin-Signed Financial Data to Smart Contracts

We are proud to announce that [Twelve Data](https://twelvedata.

April 23, 2020

Twelve Data Excel Add-in Documentation

This documentation is designed to show the proper setup and the outstanding features of the Twelve Data Excel Add-in.

April 23, 2020

Twelve Data Excel Add-in Installation Guide for Windows

Installation is super fast and intuitive; it will take not more than 1 minute.