{"id":5510,"library":"ta-lib","title":"TA-Lib (Python Wrapper)","description":"TA-Lib is a Python wrapper for the widely-used TA-Lib C library, designed for technical analysis of financial market data. It provides over 150 indicators and candlestick pattern recognition functions, optimized for performance using Cython and NumPy. The current Python wrapper version is 0.6.8, and it maintains compatibility branches for different NumPy and underlying C TA-Lib versions.","status":"active","version":"0.6.8","language":"en","source_language":"en","source_url":"https://github.com/TA-Lib/ta-lib-python","tags":["financial analysis","technical analysis","trading","numpy","pandas","cython"],"install":[{"cmd":"pip install TA-Lib","lang":"bash","label":"Python Package"},{"cmd":"# IMPORTANT: The TA-Lib C library is a REQUIRED system dependency.\n# Instructions vary significantly by OS. Examples:\n\n# macOS (using Homebrew):\nbrew install ta-lib\n\n# Linux (Debian-based, requires build tools):\nsudo apt-get update\nsudo apt-get install build-essential\n# Then, download and build the C library from http://ta-lib.org/ (latest 0.4.0-src.tar.gz or 0.6.x-src.tar.gz)\n# tar -xzf ta-lib-0.x.x-src.tar.gz\n# cd ta-lib-0.x.x\n# ./configure --prefix=/usr/local\n# make\n# sudo make install\n\n# Windows (complex, requires Visual Studio C++ build tools):\n# 1. Download ta-lib-0.4.0-msvc.zip from http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-msvc.zip\n# 2. Extract to C:\\ta-lib\n# 3. Open 'x64 Native Tools Command Prompt for VS 20XX' (matching your VS version)\n# 4. cd C:\\ta-lib\\c\\make\\cdr\\win32\\msvc\n# 5. nmake\n\n# Conda (recommended for easier dependency management):\nconda install -c conda-forge ta-lib libta-lib","lang":"bash","label":"TA-Lib C Library (System Dependency)"}],"dependencies":[{"reason":"The Python wrapper for TA-Lib is built with Cython and NumPy for efficient numerical operations and array handling.","package":"numpy","optional":false},{"reason":"This Python package is a wrapper around the original TA-Lib C library, which must be installed separately on the system.","package":"TA-Lib (C Library)","optional":false}],"imports":[{"symbol":"talib","correct":"import talib"},{"symbol":"MA_Type","correct":"from talib import MA_Type"}],"quickstart":{"code":"import numpy as np\nimport talib\nimport pandas as pd\n\n# Simulate some financial close prices\nnp.random.seed(42)\nclose_prices = np.random.rand(100) * 100 + 50\n\n# Calculate Simple Moving Average (SMA)\nsma = talib.SMA(close_prices, timeperiod=10)\nprint(\"SMA (first 15 values):\", sma[:15])\n\n# Calculate Relative Strength Index (RSI)\nrsi = talib.RSI(close_prices, timeperiod=14)\nprint(\"RSI (first 15 values):\", rsi[:15])\n\n# TA-Lib functions return NaN for initial 'lookback' periods\n# Example with Pandas Series input\ndf = pd.DataFrame({'Close': close_prices})\ndf['SMA'] = talib.SMA(df['Close'], timeperiod=10)\nprint(\"\\nDataFrame with SMA (first 15 rows):\\n\", df.head(15))","lang":"python","description":"This quickstart demonstrates calculating common technical indicators like Simple Moving Average (SMA) and Relative Strength Index (RSI) using `ta-lib` with both NumPy arrays and Pandas Series as input. Note that `ta-lib` functions return `NaN` for the initial 'lookback' periods where insufficient data is available to compute the indicator."},"warnings":[{"fix":"Follow the platform-specific instructions for installing the TA-Lib C library (e.g., Homebrew for macOS, build from source for Linux, Visual Studio compilation for Windows) before running `pip install TA-Lib`.","message":"The Python `ta-lib` package is a wrapper for an *external* C library. You must install the TA-Lib C library on your system *before* installing the Python package. Failure to do so is the most common cause of installation errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Check the `ta-lib-python` GitHub README or PyPI page for exact compatibility matrix. Consider using `conda` (`conda install -c conda-forge ta-lib libta-lib`) as it often handles these dependencies more smoothly.","message":"Version compatibility between the Python `ta-lib` wrapper, NumPy, and the underlying TA-Lib C library is crucial. Mismatches can lead to build failures or runtime errors. Specifically, `ta-lib-python 0.6.x` supports TA-Lib C library `0.6.x` and NumPy `2`.","severity":"breaking","affected_versions":"All versions, especially when upgrading Python, NumPy, or TA-Lib C library."},{"fix":"Use a compatible version of the Python `ta-lib` wrapper (e.g., `0.6.x` for the C library `0.6.x`) or ensure your C library build and linking paths are correctly configured for the Python wrapper's expectations.","message":"The underlying TA-Lib C library changed its linker name from `-lta_lib` to `-lta-lib` in version 0.6.1. If you compile the C library manually, ensure it aligns with the Python wrapper version you are using, or you may face linkage errors.","severity":"breaking","affected_versions":"TA-Lib C library 0.6.1+ with older Python wrappers."},{"fix":"Always check the output arrays for `NaN` values, especially at the beginning. Use methods like `dropna()` from Pandas if working with DataFrames, or slice your NumPy arrays to exclude the initial `NaN`s.","message":"TA-Lib functions calculate indicators over a 'lookback' period. For the initial data points within this period, the indicator cannot be computed and the functions will return `NaN` (Not a Number). Ensure your data processing handles these `NaN` values appropriately.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you have the 'Desktop development with C++' workload installed in Visual Studio. For easier installation, many users resort to downloading pre-compiled `.whl` files for their specific Python version and architecture from unofficial sources (e.g., Gohlke's Python wheels, though availability varies) or using Conda.","message":"On Windows, direct `pip install ta-lib` often fails if the C++ build tools are not correctly set up or if the 32-bit C library is installed with a 64-bit Python environment (or vice-versa).","severity":"gotcha","affected_versions":"All versions on Windows"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}