We’ve just launched a new portal to help you explore stocks, crypto, ETFs, and more data
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