Python wrapper for TA-LIB providing 175+ technical analysis indicators for financial market data
npx @tessl/cli install tessl/pypi-ta-lib@0.6.0TA-Lib is a comprehensive Python wrapper for the TA-LIB C library, providing 175+ technical analysis indicators for financial market data analysis. This library is widely used by trading software developers requiring professional-grade technical analysis of financial data, offering efficient computations that are 2-4 times faster than alternative implementations.
pip install TA-Libimport talibFor abstract interface:
import talib.abstract
from talib.abstract import FunctionFor streaming API:
import talib.stream
from talib import streamimport talib
import numpy as np
# Create sample OHLC data
close = np.random.random(100)
high = np.random.random(100)
low = np.random.random(100)
open_prices = np.random.random(100)
# Calculate simple moving average
sma = talib.SMA(close, timeperiod=30)
# Calculate RSI
rsi = talib.RSI(close, timeperiod=14)
# Calculate Bollinger Bands
upper, middle, lower = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2)
# Calculate MACD
macd, macdsignal, macdhist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)TA-Lib provides three distinct APIs for different use cases:
All functions support numpy arrays as primary input, with automatic conversion from pandas Series and polars Series. The library handles initialization and cleanup automatically, with robust NaN propagation and lookback period management.
Trend-following indicators and moving averages that smooth price data to identify trends and provide support/resistance levels. Includes moving averages, Bollinger Bands, and trend line indicators.
def SMA(real, timeperiod=30): ...
def EMA(real, timeperiod=30): ...
def BBANDS(real, timeperiod=5, nbdevup=2, nbdevdn=2, matype=MA_Type.SMA): ...
def KAMA(real, timeperiod=30): ...
def SAR(high, low, acceleration=0, maximum=0): ...Oscillators and momentum-based indicators that measure the rate of price change and help identify overbought/oversold conditions and potential reversal points.
def RSI(real, timeperiod=14): ...
def MACD(real, fastperiod=12, slowperiod=26, signalperiod=9): ...
def STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=MA_Type.SMA, slowd_period=3, slowd_matype=MA_Type.SMA): ...
def ADX(high, low, close, timeperiod=14): ...
def CCI(high, low, close, timeperiod=14): ...
def IMI(open, close, timeperiod=14): ...Indicators that analyze the relationship between price movements and trading volume to confirm trends and identify potential reversals.
def AD(high, low, close, volume): ...
def OBV(close, volume): ...
def ADOSC(high, low, close, volume, fastperiod=3, slowperiod=10): ...Measures of price volatility and range to assess market conditions and potential breakout scenarios.
def ATR(high, low, close, timeperiod=14): ...
def NATR(high, low, close, timeperiod=14): ...
def TRANGE(high, low, close): ...
def ACCBANDS(high, low, close, timeperiod=20): ...Candlestick pattern recognition functions that identify traditional Japanese candlestick patterns for technical analysis and trading signals.
def CDLDOJI(open, high, low, close): ...
def CDLHAMMER(open, high, low, close): ...
def CDLENGULFING(open, high, low, close): ...
def CDLMORNINGSTAR(open, high, low, close, penetration=0): ...
def CDL3BLACKCROWS(open, high, low, close): ...Functions that transform OHLC data into standardized price representations for further analysis.
def AVGPRICE(open, high, low, close): ...
def MEDPRICE(high, low): ...
def TYPPRICE(high, low, close): ...
def WCLPRICE(high, low, close): ...Hilbert Transform-based indicators for cycle analysis and trend vs cycle mode determination.
def HT_DCPERIOD(real): ...
def HT_SINE(real): ...
def HT_TRENDMODE(real): ...
def HT_PHASOR(real): ...
def HT_DCPHASE(real): ...Statistical analysis functions for correlation, regression, and statistical measures of price data.
def BETA(real0, real1, timeperiod=5): ...
def CORREL(real0, real1, timeperiod=30): ...
def LINEARREG(real, timeperiod=14): ...
def STDDEV(real, timeperiod=5, nbdev=1): ...
def VAR(real, timeperiod=5, nbdev=1): ...
def AVGDEV(real, timeperiod=14): ...Mathematical transformation and operator functions for array manipulation and calculations.
def ADD(real0, real1): ...
def SUM(real, timeperiod=30): ...
def MAX(real, timeperiod=30): ...
def MIN(real, timeperiod=30): ...
def SQRT(real): ...
def SIN(real): ...
def LOG10(real): ...Alternative interfaces providing flexible DataFrame support and real-time processing capabilities.
# Abstract API
class Function:
def __init__(self, function_name, *args, **kwargs): ...
# Streaming functions return single values
def stream_SMA(real, timeperiod=30): ... # Returns latest SMA value onlyfrom enum import Enum
from typing import Tuple
import numpy as np
class MA_Type(Enum):
"""Moving Average Types"""
SMA = 0 # Simple Moving Average
EMA = 1 # Exponential Moving Average
WMA = 2 # Weighted Moving Average
DEMA = 3 # Double Exponential Moving Average
TEMA = 4 # Triple Exponential Moving Average
TRIMA = 5 # Triangular Moving Average
KAMA = 6 # Kaufman Adaptive Moving Average
MAMA = 7 # MESA Adaptive Moving Average
T3 = 8 # Triple Exponential Moving Average (T3)
# Type aliases
NDArray = np.ndarray
PriceArray = np.ndarray[np.float64]
IntArray = np.ndarray[np.int32]def get_functions() -> list[str]:
"""Returns a list of all supported TA-Lib function names"""
def get_function_groups() -> dict[str, list[str]]:
"""Returns functions organized by group (e.g., 'Overlap Studies', 'Momentum Indicators')"""
def set_unstable_period(func_id: int, period: int) -> None:
"""Set unstable period for a function"""
def get_unstable_period(func_id: int) -> int:
"""Get unstable period for a function"""
def set_compatibility(value: int) -> None:
"""Set compatibility mode"""
def get_compatibility() -> int:
"""Get compatibility mode"""