Skip to main content

bartons

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

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
CMO(period=14) Rolling-window Chande Momentum Oscillator
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) Normalized Average True Range (%)
OBV() On-Balance Volume
PPO(fast=12, slow=26) 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) Rate of Change (%)
ROCP(period=1) Rate of Change as an unscaled fraction
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
STOCHRSI(period=14, fastn=3, slown=3) Stochastic RSI, fast K and fast D
STREAK(src) Consecutive true count
SUPERTREND(period=10, multiplier=3.0) Supertrend line and bullish/bearish direction
TEMA(period=20) Triple exponential moving average
TRANGE() True range
TRIX(period=30) Triple-smoothed EMA rate of change (%)
TYPPRICE() Typical price, (high + low + close) / 3
ULTOSC(fast=7, medium=14, slow=28) Ultimate Oscillator
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.5.tar.gz (612.7 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.5-cp311-abi3-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.11+Windows x86-64

bartons-0.1.5-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.5-cp311-abi3-manylinux_2_28_aarch64.whl (7.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.11+macOS 11.0+ ARM64

bartons-0.1.5-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.5.tar.gz.

File metadata

  • Download URL: bartons-0.1.5.tar.gz
  • Upload date:
  • Size: 612.7 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.5.tar.gz
Algorithm Hash digest
SHA256 59047e915c9ecd86039455c53be110caaf1907bb027ac73747f525a30f68de6b
MD5 e2c96aa6d59526e451a6291d66099b1e
BLAKE2b-256 104297f4074bee73f413a0a8c5e40141a4675ca54d6f0cf7c8e8a38833b49aed

See more details on using hashes here.

Provenance

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

Publisher: release.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.5-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: bartons-0.1.5-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.5 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.5-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 13edef47f4586cb74c81daa95eca57d6217cb4825c53ad6fbe9c2ff17b128618
MD5 3dca81185051c5cc38f0468e624c06f0
BLAKE2b-256 e80775fcb12ff8694f95d627f1264df4ec8f64f1aef2c54d74dc9a1aaa40203c

See more details on using hashes here.

Provenance

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

Publisher: release.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.5-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bartons-0.1.5-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6b9b21a399746487eaef42fa65cf0d6f6d1bada84156bc886a10f4b97af92b2
MD5 8ba4439ade6076e02f56d669a7869428
BLAKE2b-256 c18141dcd0e043f00fb5b236a99aec17ec6894c730d3b48a34dba5617b30e916

See more details on using hashes here.

Provenance

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

Publisher: release.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.5-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bartons-0.1.5-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ac3a95287204f62820d43a1e8d82840a973a4ddba429b8962188d44267a9bf3a
MD5 97c3b83e85fe1a0c226964ab22639cdc
BLAKE2b-256 74555d9353190b2be21b7e4b08c624478df2ef0b01f36a5e2dc9d1b2c210cd06

See more details on using hashes here.

Provenance

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

Publisher: release.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.5-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bartons-0.1.5-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d66bfc70cc64ec91669665a78311092c798d7e867d30d49c8bd7b8d53dba56e9
MD5 a9a4ea199b7d883a1dbe0ee1ed00f6e6
BLAKE2b-256 88ad90c65a1a1da7b9c8c2536de281b9f6489381ac6f2486cc089d6035660429

See more details on using hashes here.

Provenance

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

Publisher: release.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.5-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bartons-0.1.5-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bbb439638bd854e7761b5bf8b06d0c7e32cc3308ab7a431f59da5e5daf5c4558
MD5 fe9daee5f893069adb865e75f90ea5c2
BLAKE2b-256 bc6a90d17be05d29bd7c0a91016e4e665bad25e8fed415594bf895e2cf3ee963

See more details on using hashes here.

Provenance

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

Publisher: release.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

This release

0.1.5 This release

6 files

0.1.4

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