polars-talib-fast
Every TA-Lib function, 237 of them, as a Polars
expression. TA-Lib comes from ta-lib, TA-Lib's official
Rust port.
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 about the same on both (EMA: 1.7 ms here, 2.2 ms with ta-lib-python 0.8.2). Per symbol
it is: under .over("symbol") the plugin runs the function per group without a Python call.
The comparison with thousands of symbols and with several indicators in one select is in
ARCHITECTURE.md, section 6.
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 API: inputs, parameters
with defaults, outputs, group, hint. This library has one Rust expression that runs
any TA-Lib function by name through that API, 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 version bump of the ta-lib crate plus new golden test data from the C library at the
same tag:
# Cargo.toml: ta-lib = "=<version>"
git -C tools/c_oracle/ta-lib checkout v<version>
tools/c_oracle/generate.sh # golden data from the C library
uv sync # builds the extension
uv run python -m polars_talib_fast._stubs # regenerate the .pyi stubs
uv run pytest
Install
Windows x64, Linux x64 (glibc 2.17 or newer) and macOS on Apple silicon, Python 3.10 or newer:
pip install polars-talib-fast
The same wheels are attached to each
release. All three platforms run
the full test suite in CI; Linux is also run locally in WSL2 with tools/wsl_test.sh.
Tests
The oracle is TA-Lib's C library at the same tag as the crate. tools/c_oracle builds it
and writes tests/golden, and the oracle itself is checked against ta-lib-python, bit for bit,
on the TA-Lib versions ta-lib-python ships (0.7.1 and 0.8.1). Every function is checked for
the description TA-Lib's C library gives (names, defaults, hints, outputs) 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 values are per platform: the
functions that call sin, exp or log follow the platform's math library in the last bit,
and on each platform the C library and the crate agree bit for bit (Windows and Linux golden
data are committed, Linux written in WSL by tools/c_oracle/wsl_generate.sh; the macOS CI job
writes its own). ta-lib-python 0.8.2 checks the names and signatures of the 201 functions it
has. supersmoother, which TA-Lib does not have, is
checked against its recursion.
Beyond TA-Lib
supersmoother (Ehlers' 2-pole low-pass filter, with AmiBroker's IIR() coefficients) is a
Rust expression of its own in src/extra.rs. An indicator lives here only while TA-Lib does
not have it: hma was one until TA-Lib 0.8 added HMA, which a test shows to be the same
Hull composition.
Build
git clone https://github.com/meet-brad-ch/polars-talib-fast
uv sync # builds the extension
uv run pytest
Needs a Rust toolchain and, for the tests, Python 3.11 or newer (ta-lib-python 0.8.2, one
of the oracles, has no wheel for 3.10). The C oracle (tools/c_oracle, only for new golden data) also needs
the submodule (git submodule update --init) and a C compiler.
License
MIT. The wheels contain TA-Lib, BSD-3-Clause, Copyright (c) 1999-2026 Mario Fortier: LICENSES/TA-Lib.txt.
The idea of exposing TA-Lib as Polars expressions comes from Yvictor/polars_ta_extension.
Metadata
Release files for polars-talib-fast 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polars_talib_fast-2.0.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for polars_talib_fast-2.0.0-cp310-abi3-win_amd64.whl |
| polars_talib_fast-2.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details for polars_talib_fast-2.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| polars_talib_fast-2.0.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for polars_talib_fast-2.0.0-cp310-abi3-macosx_11_0_arm64.whl |
Total release size: 15.0 MB
Release files / polars_talib_fast-2.0.0-cp310-abi3-win_amd64.whl
| Download URL | polars_talib_fast-2.0.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 5.3 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5705bcac3f8e782e83cd94a6a048eaf53dd83b771c4a007a02f1954b51d7a79c
|
|
BLAKE2b-256 checksum How to use checksums |
f6f58b5c74aea28805c8fca3c1e146c931516c4af5026a784e9d6f0ce7998f80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 26, 2026.
Transparency logRelease files / polars_talib_fast-2.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | polars_talib_fast-2.0.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1179353d30f2c3274ebd40f0d0517dfb2049cab6b4d606db30b3e61c532ca248
|
|
BLAKE2b-256 checksum How to use checksums |
2cc1ece569efa8816943f6ae2e0c0ff70c74126aa7b5dab2d86fcf38bdd58930
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 26, 2026.
Transparency logRelease files / polars_talib_fast-2.0.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | polars_talib_fast-2.0.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8b3fd2165bef93da309d429f090fc8dcec1217c16b10a89956032781d51ba75b
|
|
BLAKE2b-256 checksum How to use checksums |
0f8c28e9ef048ae2a04bb011863cfdc7e4b3c4e9d27c23299946d46e365ac269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 26, 2026.
Transparency logSecurity for polars-talib-fast 2.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
All 3 files in this release have been uploaded with provenance metadata.
Attestation for polars_talib_fast-2.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 Oct 26, 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.