Skip to main content

bartons

Financial and technical-analysis expressions for polars, implemented in Rust as a native plugin (PyO3 + maturin).

PyPI · Source · Issues · Changelog

Each indicator is a factory returning a pl.Expr, so it composes with the rest of polars — inside select, with_columns, over, lazy frames, and so on.

Install

Requires Python 3.11+ and polars>=1.28,<1.44. Wheels are cp311-abi3, so one wheel per platform covers every Python from 3.11 up. Prebuilt wheels support Linux x86_64 and ARM64, macOS Intel and Apple silicon, and Windows x64; other platforms can build from the sdist with a Rust toolchain.

pip install bartons

Usage

import polars as pl
from bartons.indicators import ATR, CCI, DMI, EMA, MACD, RSI, SMA, TYPPRICE
from bartons.samples import sample_prices

prices = sample_prices("daily")

prices.select("date", "close", EMA(20), RSI(14), ATR(14)).tail(3)
┌────────────┬────────────┬────────────┬───────────┬──────────┐
│ date       ┆ close      ┆ ema        ┆ rsi       ┆ atr      │
╞════════════╪════════════╪════════════╪═══════════╪══════════╡
│ 2024-08-07 ┆ 209.820007 ┆ 217.642081 ┆ 40.192313 ┆ 6.920431 │
│ 2024-08-08 ┆ 213.309998 ┆ 217.229501 ┆ 45.237928 ┆ 6.809686 │
│ 2024-08-09 ┆ 216.240005 ┆ 217.135264 ┆ 49.118920 ┆ 6.666851 │
└────────────┴────────────┴────────────┴───────────┴──────────┘

Conventions

Price frames use a date or datetime column followed by lowercase open, high, low, close, and volume columns. Indicators refer to these lowercase OHLCV names by default; pass explicit column names or expressions when your schema differs.

Each indicator names its output after itself in lowercase like ema, sma ... Use explicit aliases to avoid name collisions:

prices.with_columns(EMA(20), SMA(20))                     # -> "ema", "sma"
prices.with_columns(EMA(20).alias("fast"), EMA(50).alias("slow"))

Single-source indicators typically default to pl.col("close") as source, but they also accept an explicit source, either as the first positional argument or via the src keyword, which makes them chainable with pipe:

EMA(20)                                     # default source
EMA(pl.col("close"), 20)                    # explicit source (positional)
EMA(20, src=pl.col("close"))                # explicit source (src keyword)
pl.col("close").pipe(EMA, 20)               # chaining with pipe

TRANGE, ATR and the price transforms like TYPPRICE accept multiple inputs like high, low and close, each overridable via keyword arguments:

TYPPRICE()                              # high, low and close
TYPPRICE(high="h", low="l", close="c")  # other column names

CCI is a single-source indicator, but defaults its source to TYPPRICE() rather than pl.col("close"):

CCI(20)                          # typical price by default
CCI(20, src=TYPPRICE())          # same thing

Indicators

ADL() Accumulation/Distribution Line
ADOSC(fast=3, slow=10) Chaikin A/D Oscillator
ALMA(period=9, offset=0.85, sigma=6.0) Arnaud Legoux moving average
AROON(period=14) Aroon Down and Up
AROONOSC(period=14) Aroon Oscillator
ATR(period) Average true range
AVGPRICE() Average price, (open + high + low + close) / 4
BBANDS(period=20, nbdev=2.0) Bollinger upper, middle and lower bands
BBP(period=20, nbdev=2.0) Bollinger Percent B ratio
BBW(period=20, nbdev=2.0) Bollinger BandWidth ratio
BOP() Unsmoothed Balance of Power
CCI(period=20) Commodity Channel Index
CMF(period=20) Chaikin Money Flow
DEMA(period) Double exponential moving average
DMI(period=14) ADX, plus DI and minus DI expressions
DONCHIAN(period=20) Donchian upper, middle and lower channels
EMA(period) Exponential moving average
HMA(period) Hull moving average
KAMA(period=10, fastn=2, slown=30) Kaufman adaptive moving average
KELTNER(period=20, nbatr=2.0) Keltner upper, middle and lower channels
KER(period=10) Kaufman efficiency ratio
LINREG(period=20, offset=0) Rolling linear-regression forecast
LINREG_RMSE(period=20) Rolling linear-regression RMSE
LINREG_RVALUE(period=20) Rolling linear-regression r-value
LINREG_SLOPE(period=20) Rolling linear-regression slope
MACD(fast=12, slow=26, signal=9) MACD, signal and histogram expressions
MAD(period=20) Rolling mean absolute deviation
MEDPRICE() Median price, (high + low) / 2
MFI(period=14) Money Flow Index
MOM(period=1) Momentum
NATR(period=14) Raw fractional normalized average true range
OBV() On-Balance Volume
PPO(fast=12, slow=26) Raw fractional Price Percentage Oscillator
QUADREG(period=20, offset=0) Rolling quadratic-regression forecast
QUADREG_CURVE(period=20) Rolling quadratic coefficient
QUADREG_RMSE(period=20) Rolling quadratic-regression RMSE
QUADREG_RVALUE(period=20) Rolling quadratic partial r-value
QUADREG_SLOPE(period=20, offset=0) Rolling quadratic-regression slope
RMA(period) Wilder's running moving average
ROC(period=1) Raw fractional rate of change
RSI(period) Wilder's relative strength index
SAR(afs=0.02, maxaf=0.2) Parabolic Stop and Reverse
SMA(period) Simple moving average
STOCH(period=14, fastn=3, slown=3) Slow stochastic oscillator, %K and %D
STREAK(src) Consecutive true count
TEMA(period=20) Triple exponential moving average
TRANGE() True range
TYPPRICE() Typical price, (high + low + close) / 3
WCLPRICE() Weighted close price, (high + low + 2 * close) / 4
WILLR(period=14) Williams %R
WMA(period) Weighted moving average
ZLEMA(period) Zero-lag exponential moving average

Multi-output indicators return a Polars struct expression. You can unpack its fields directly in the query:

prices.select("date", MACD().struct.unnest())

Or keep the struct column in the query result and unnest it afterward:

result = prices.select("date", MACD())  # contains "macd" struct column
result.unnest()

Bare .unnest() expands every struct column; pass a column name such as .unnest("macd") to expand only that struct. The resulting field names must not collide with existing columns.

Eager API

The compiled kernels are also callable directly on polars series, bypassing the expression layer:

from bartons import kernels

kernels.ema(prices["close"], period=20)
kernels.dmi(prices["high"], prices["low"], prices["close"]).struct.unnest()

Parameters are keyword-only here. This path needs polars>=1.28; the expression API alone works further back.

Development

Set up the development environment and run the complete source-tree validation:

uv sync
uv run inv make

Run the Rust and Python tests without regenerating the extension and stubs:

uv run inv test

License

Bartons is available under the MIT License.

Related Projects

  • polars-talib — a Polars extension exposing TA-Lib indicators and candlestick-pattern functions as Polars expressions.
  • polars-ta — an expression-oriented collection of technical-analysis, WorldQuant, and Tongdaxin operators for Polars.
  • Polars — a fast DataFrame library with Rust and Python APIs, an expression engine, lazy query optimization, and Arrow-compatible memory.
  • PyO3 — Rust bindings for creating native Python modules and calling between Rust and Python.
  • Maturin — a build and publishing tool for Python packages implemented in Rust.

Download files

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

Source Distribution

bartons-0.1.4.tar.gz (609.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bartons-0.1.4-cp311-abi3-win_amd64.whl (6.4 MB view details)

Uploaded CPython 3.11+Windows x86-64

bartons-0.1.4-cp311-abi3-manylinux_2_28_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

bartons-0.1.4-cp311-abi3-manylinux_2_28_aarch64.whl (7.1 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

bartons-0.1.4-cp311-abi3-macosx_11_0_arm64.whl (6.3 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

bartons-0.1.4-cp311-abi3-macosx_10_12_x86_64.whl (6.3 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file bartons-0.1.4.tar.gz.

File metadata

  • Download URL: bartons-0.1.4.tar.gz
  • Upload date:
  • Size: 609.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for bartons-0.1.4.tar.gz
Algorithm Hash digest
SHA256 037a477913e87a1e6a6fa1a7eb187ac7e80fdebe6058a22cb3cde14b95449bf2
MD5 73042fcefea65f30c2c26e378e4b0c1e
BLAKE2b-256 03bfcf2eec716dd5893301411eaadf55409667acb0ed0f7127eaf5e4ca776633

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.4.tar.gz:

Publisher: publish.yml on furechan/bartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bartons-0.1.4-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: bartons-0.1.4-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.4 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for bartons-0.1.4-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9452bf61fa5d3881d30f02cdfb490abbe3f65f0ec25d8efc7eb37e3a17db5535
MD5 9c709904b8cedb286ae910da8fedc34b
BLAKE2b-256 582599e19262f44e1f2ced181ea95d7c6a71c5ff45c327d347a1f18b24440ebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.4-cp311-abi3-win_amd64.whl:

Publisher: publish.yml on furechan/bartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bartons-0.1.4-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bartons-0.1.4-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cbdd4ca7ca1bc2440ff8356ce3bb8dd6609c362039be463c003242a1238aec56
MD5 0659d23dce25d1994a9894e5d5650f52
BLAKE2b-256 6acda777c03ad94a05e13299f96dc088dbbb8692720aab08aef0beee640f96e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.4-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on furechan/bartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bartons-0.1.4-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bartons-0.1.4-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 42cce615c3fd1ff715684c17e5f4e8271f3409b389db0028a6e7e48f219de07d
MD5 ec8c464aceaf8db8cb5662f8f4c5ca41
BLAKE2b-256 caf3a5620fc44da8f0df2eb0f007ef3106a52f748a558c1ceb8ef9765d501d1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.4-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on furechan/bartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bartons-0.1.4-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bartons-0.1.4-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76beabb4a1f79427e24ca419cfa3bf590a0e208dbbb53395711a63dbafa89326
MD5 ef0f63eb04f63aa5158e419532a21f08
BLAKE2b-256 7c3541572449d0e8985174d172f769c2a648e3e8776cd25a9e40b906dcb3d5d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.4-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on furechan/bartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bartons-0.1.4-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bartons-0.1.4-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 baeb5e57a5c94d000408b09e12d1efb5c4f0211657f67db2fcb89eb63e0072ac
MD5 f9fba14208def2644cb2255c526c4b40
BLAKE2b-256 1358e36d892697be4f080a412b2ec2f5b3054ccd8ac55a2b71c3ca750f9b744d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.4-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on furechan/bartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.7

6 files

0.1.6

6 files

0.1.5

6 files

This release

0.1.4 This release

6 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page