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
ADX(period=14) Average Directional Index
ALMA(period=9, offset=0.85, sigma=6.0) Arnaud Legoux moving average
APO(fast=12, slow=26, matype="ema") Absolute Price Oscillator
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
CLAG(period=1) Confirmation lag for discrete states
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
LROC(period=1) Logarithmic Rate of Change
MA(period=30, matype="sma") Generic moving-average dispatcher
MACD(fast=12, slow=26, signal=9) MACD, signal and histogram expressions
MAD(period=20) Rolling mean absolute deviation
MDI(period=14) Negative Directional Indicator
MEDPRICE() Median price, (high + low) / 2
MFI(period=14) Money Flow Index
MIDPRICE(period=14) Midpoint of the rolling highest high and lowest low
MOM(period=1) Momentum
NATR(period=14) Normalized Average True Range (%)
OBV() On-Balance Volume
PDI(period=14) Positive Directional Indicator
PPO(fast=12, slow=26, matype="ema") 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
STEP(threshold=1.0) Threshold-limited step function
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
VWMA(period=20) Volume-weighted moving average
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.

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.6.tar.gz (615.6 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.6-cp311-abi3-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.11+Windows x86-64

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

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

bartons-0.1.6-cp311-abi3-macosx_11_0_arm64.whl (6.4 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

bartons-0.1.6-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.6.tar.gz.

File metadata

  • Download URL: bartons-0.1.6.tar.gz
  • Upload date:
  • Size: 615.6 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.6.tar.gz
Algorithm Hash digest
SHA256 615f5d2effb8e97d920cdf48c0ee62d77b196cbcecc746b293dfef34bea87e69
MD5 9b37857ee71a3bfc2c6c85c1be867fc5
BLAKE2b-256 ad25b23a0c3f6cacbc04df2d600611bc63ccaa23e0ff9b558d51f8660655b31c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.6.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.6-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: bartons-0.1.6-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.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b2cebb549681169efadd22dbc1c7e935278b1ae8f090a07862bbf9e3196e7359
MD5 e296c3b997ed0bbfde878ed9b314a430
BLAKE2b-256 d8cfe358ef1bafcb41d9b2366f91565365f5e760f259083037a4179772debb1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.6-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.6-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bartons-0.1.6-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0421a8283288b86b09a972f403bff4d3a11d2856881ae8b62781a4f6fa817ac5
MD5 fe55bf5a15f95081480d0a6535df5f3a
BLAKE2b-256 60080b523d11474a1548fba7973d8cef754211ae120b0395112e66f31ea53d3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.6-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.6-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bartons-0.1.6-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 468856609acfb1d5335b7e2102b082cd5a92ffa2441ffd1b2d2fcb96b5998423
MD5 aef88532a3b15c132db87b0183061148
BLAKE2b-256 6c283e010ef7d847163fb8ac47f58c3a499f8d14bfeaa04e909a944858176a55

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.6-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.6-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bartons-0.1.6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb389ceeaed83a87aa1fe91af56fbed487456ff577bc8596ff25d22b231d9943
MD5 997735d0325dd500fa8512dd22a531bc
BLAKE2b-256 4ada0f669a25ad5a4e3df80224af46911a516c5ace78be5349bef122aaff4e21

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.6-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.6-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bartons-0.1.6-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a3eece49054eae9e1a9a2f8a3b1bbb964dc90fb323f3e7b19ab4ed3b7f7a7825
MD5 449a6f3e83e4f26aa0d7701fba7052e2
BLAKE2b-256 ca3532e71e7dd31c761b4d213819633f664336f101fee42e9f049b6bacb985af

See more details on using hashes here.

Provenance

The following attestation bundles were made for bartons-0.1.6-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

This release

0.1.6 This release

6 files

0.1.5

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