Skip to main content

Python client for Twelve Data API

Project description

Build Status Open Issues Latest Stable Version License

Twelve Data API

Official python library for Twelve Data API. This package supports all main features of the API:

  • Get stock, forex and cryptocurrency OHLC time series.
  • Get over 90+ technical indicators.
  • Output data as: json, csv, pandas
  • Full support for static and dynamic charts.

chart example

Free API Key is required. It might be requested here


Use the package manager pip to install Twelve Data API library (without optional dependencies):

pip install twelvedata

Or install with pandas support:

pip install twelvedata[pandas]

Or install with pandas, matplotlib and plotly support used for charting:

pip install twelvedata[pandas,matplotlib,plotly]


Supported parameters
Parameter Description Type Required
symbol stock ticker (e.g. AAPL, MSFT);
physical currency pair (e.g. EUR/USD, CNY/JPY);
digital currency pair (BTC/USD, XRP/ETH)
string yes
interval time frame: 1min, 5min, 15min, 30min, 45min, 1h, 2h, 4h, 8h, 1day, 1week, 1month string yes
apikey your personal API Key, if you don't have one - get it here string yes
exchange if symbol is traded in multiple exchanges specify the desired one, valid for both stocks and cryptocurrencies string no
country if symbol is traded in multiple countries specify the desired one, valid for stocks string no
outputsize number of data points to retrieve int no
timezone timezone at which output datetime will be displayed, supports: UTC, Exchange or according to IANA Time Zone Database string no
start_date start date and time of sampling period, accepts yyyy-MM-dd or yyyy-MM-dd hh:mm:ss format string no
end_date end date and time of sampling period, accepts yyyy-MM-dd or yyyy-MM-dd hh:mm:ss format string no

Time series

  • TDClient requires api_key parameter. It accepts all common parameters.
  • TDClient.time_series() accepts all common parameters. Time series may be converted to several formats:
    • TDClient.time_series().as_json() - will return JSON array
    • TDClient.time_series().as_csv() - will return CSV with header
    • TDClient.time_series().as_pandas() - will return pandas.DataFrame
from twelvedata import TDClient
# Initialize client - api_key parameter is requiered
td = TDClient(apikey="YOUR_API_KEY_HERE")
# Construct the necessary time serie
ts = td.time_series(
# Returns pandas.DataFrame

Technical indicators

This Python library supports all indicators implemented by Twelve Data. Full list of 90+ technical indicators may be found in API Documentation.

  • Technical indicators are part of TDClient.time_series() object.
  • It has universal format TDClient.time_series().with_{Technical Indicator Name}, e.g. .with_bbands(), .with_percent_b(), .with_macd()
  • Indicator object accepts all parameters according to its specification in API Documentation, e.g. .with_bbands() accepts: series_type, time_period, sd, ma_type. If parameter is not provided it will be set to default.
  • Indicators may be used in arbitrary order and conjugated, e.g. TDClient.time_series().with_aroon().with_adx().with_ema()
  • By default, technical indicator will output with OHLC values. If you do not need OHLC, specify TDClient.time_series().without_ohlc()
from twelvedata import TDClient

td = TDClient(apikey="YOUR_API_KEY_HERE")
ts = td.time_series(
# Returns: OHLC, BBANDS(close, 20, 2, EMA), PLUS_DI(9), WMA(20), WMA(40)

# Returns: STOCH(14, 1, 3, SMA, SMA), TSF(close, 9)


Charts support OHLC, technical indicators and custom bars.


Static charting is based on matplotlib library. Make sure you have installed it.

  • Use .as_pyplot_figure()
from twelvedata import TDClient

td = TDClient(apikey="YOUR_API_KEY_HERE")
ts = td.time_series(
# 1. Returns OHLCV chart

# 2. Returns OHLCV + BBANDS(close, 20, 2, SMA) + %B(close, 20, 2 SMA) + STOCH(14, 3, 3, SMA, SMA)


Interactive charting is based on plotly library. Make sure you have installed it.

  • Use .as_plotly_figure()
from twelvedata import TDClient

td = TDClient(apikey="YOUR_API_KEY_HERE")
ts = td.time_series(
# 1. Returns OHLCV chart

# 2. Returns OHLCV + EMA(close, 7) + MAMA(close, 0.5, 0.05) + MOM(close, 9) + MACD(close, 12, 26, 9)


Visit our official website or reach out to the Twelve Data team at


  • [ ] Save-load chart templates
  • [ ] Auto-update charts
  • [x] Custom plots coloring
  • [x] Interactive charts (plotly)
  • [x] Static charts (matplotlib)
  • [x] Pandas support


  1. Clone repo and create a new branch: $ git checkout -b name_for_new_branch.
  2. Make changes and test.
  3. Submit Pull Request with comprehensive description of changes.


This package is open-sourced software licensed under the MIT license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for twelvedata, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size twelvedata-0.1.3-py2.py3-none-any.whl (30.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page