polars-talib-fast
Every TA-Lib function as a Polars expression.
import polars as pl
import polars_talib_fast as plta
df.with_columns(
plta.sma(timeperiod=20).alias("sma20"),
plta.macd().over("symbol").alias("macd"), # struct: macd, macdsignal, macdhist
plta.atr(pl.col("high"), pl.col("low"), pl.col("close"), timeperiod=14).alias("atr"),
plta.cdlengulfing().alias("engulfing"), # Int32, as TA-Lib reports patterns
)
Inputs default to the columns TA-Lib's own conventions name (close for a single series,
open/high/low/close/volume for price functions), parameters default to TA-Lib's
values, and multi-output functions return a struct with TA-Lib's output names. Nulls and
leading NaN rows are handled as ta-lib-python does: the output is NaN (or 0 for integer
outputs) until the function has enough data.
Or ta-lib-python?
ta-lib-python accepts a Polars Series and is
the simplest tool for one array and one indicator. Inside a Polars query it needs a
map_batches wrapper per indicator. The example above, written with ta-lib-python, gives
the same four columns:
import talib
def macd(close: pl.Series) -> pl.Series:
m, s, h = talib.MACD(close.to_numpy(), 12, 26, 9)
return pl.DataFrame({"macd": m, "macdsignal": s, "macdhist": h}).to_struct("macd")
def atr(cols: pl.Series) -> pl.Series:
c = cols.struct
return pl.Series(
talib.ATR(
c.field("high").to_numpy(), c.field("low").to_numpy(), c.field("close").to_numpy(), 14
)
)
def engulfing(cols: pl.Series) -> pl.Series:
c = cols.struct
return pl.Series(
talib.CDLENGULFING(*(c.field(k).to_numpy() for k in ("open", "high", "low", "close")))
)
MACD = pl.Struct({"macd": pl.Float64, "macdsignal": pl.Float64, "macdhist": pl.Float64})
df.with_columns(
pl.col("close")
.map_batches(lambda s: pl.Series(talib.SMA(s.to_numpy(), 20)), return_dtype=pl.Float64)
.alias("sma20"),
pl.col("close").map_batches(macd, return_dtype=MACD).over("symbol").alias("macd"),
pl.struct("high", "low", "close").map_batches(atr, return_dtype=pl.Float64).alias("atr"),
pl.struct("open", "high", "low", "close")
.map_batches(engulfing, return_dtype=pl.Int32)
.alias("engulfing"),
)
Speed is not the difference. Measured on the same machine, one indicator on a million rows
costs the same on both, and so do eight indicators in one select once ta-lib-python
releases the GIL. Per symbol it is: under .over("symbol") the plugin runs the function
per group without a Python call, and is 3 to 5 times faster with thousands of symbols.
The difference is that every function is a native expression with TA-Lib's names,
defaults, struct outputs, integer types, docstrings and type stubs, generated from TA-Lib's
own metadata.
How it works
The design is described in ARCHITECTURE.md. In short: TA-Lib describes its own functions through its abstract interface: inputs, parameters with defaults, outputs, group, hint. This library has one Rust expression that runs any TA-Lib function by name through that interface, and builds the Python API from the same metadata at import time. No function is written by hand, so a new TA-Lib release is a submodule bump:
cd ta-lib && git checkout v0.7.1 && cd ..
uv sync # builds the extension
uv run python -m polars_talib_fast._stubs # regenerate the .pyi stubs
uv run pytest
TA-Lib is compiled from the ta-lib submodule by build.rs; nothing is downloaded at
build time.
Install
Windows x64, Python 3.10 or newer:
pip install polars-talib-fast
The same wheel is attached to each release.
Tests
The oracle is ta-lib-python built on the same TA-Lib version. Every function is checked
for the exact signature TA-Lib declares and for bit-identical values on float64 and float32
input, on a synthetic frame with leading NaN rows and a null, and on TA-Lib's own 252-bar
reference data. The two functions TA-Lib does not have are checked against their
definitions: hma against the WMA composition, supersmoother against the recursion.
Beyond TA-Lib
hma (Hull Moving Average) is a composition of wma calls in Python. supersmoother
(Ehlers' 2-pole low-pass filter, with AmiBroker's IIR() coefficients) is a Rust expression
of its own in src/extra.rs. New indicators follow the same two routes; the TA-Lib layer
is never touched.
git clone --recurse-submodules https://github.com/meet-brad-ch/polars-talib-fast
uv sync # builds the extension
uv run pytest
Needs a Rust toolchain and the Visual Studio C++ build tools.
The idea of exposing TA-Lib as Polars expressions comes from Yvictor/polars_ta_extension.
Metadata
Release files for polars-talib-fast 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polars_talib_fast-1.0.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for polars_talib_fast-1.0.0-cp310-abi3-win_amd64.whl |
Release files / polars_talib_fast-1.0.0-cp310-abi3-win_amd64.whl
| Download URL | polars_talib_fast-1.0.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
cbba0dc3c36bc4c1e181aec1c1af2f6a97d252e21932a8dd627f28ea6d12bd94
|
|
BLAKE2b-256 checksum How to use checksums |
74acadde5e9b3f2b63a636abf434bff37cf41c2c15fb64c2a7133d23204828a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.
Transparency logSecurity for polars-talib-fast 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for polars_talib_fast-1.0.0-cp310-abi3-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.