Skip to main content

Pine Script-like indicators and helpers built on pandas and numpy.

Project description

pinepy

A Pine Script-like helper library for Python using only pandas and numpy.

Goals

  • Provide Pine-style series operations and indicator math in Python.
  • Stay lightweight: no dependencies beyond pandas and numpy.
  • Keep behavior close to Pine where it matters for calculations.

Non-goals (for now)

  • Chart rendering and UI (plotting is not implemented).
  • Strategy execution engine (orders, fills, slippage).
  • Real-time brokerage integration.

Status

This is a compatibility-focused subset of Pine Script v5. It prioritizes indicator calculations and series behaviors. Plotting, strategy orders, alerts, and UI inputs are stubs.

Install (editable, local dev)

pip install -e .

Install (build + install)

pip install .

Quick usage

import pandas as pd
import pinepy as pine

# Example OHLCV DataFrame
# df = pd.read_csv(...)
close = df["close"]
volume = df["volume"]

ema_20 = pine.ta.ema(close, 20)
rsi_14 = pine.ta.rsi(close, 14)

# Pine-like history reference
ema_20_prev = pine.series.ref(ema_20, 1)

Concepts

Series and history referencing

Pine uses time-series values that can be indexed like close[1] to access previous bars. In pinepy, you can do this via:

from pinepy import Series
from pinepy import series as s

close = Series(df["close"])
prev_close = close[1]         # shift by 1
prev_close_alt = s.ref(close, 1)

NA behavior

  • pinepy.math.na is numpy.nan.
  • pinepy.math.nz(x, replacement) replaces NA values.

Input stubs

Pine input.* functions are UI-driven. In pinepy, they are simple stubs that return the default value you provide.

API Overview

pinepy.series

  • Series: wrapper class with Pine-like history indexing.
  • ref(source, length=1): shift series by length.
  • nz(source, replacement=0): replace NA values.

pinepy.math

  • na: NA constant (numpy.nan).
  • isna(source)
  • nz(source, replacement=0)
  • abs(source)
  • sqrt(source)
  • pow(source, power)
  • max(source, other)
  • min(source, other)
  • avg(a, b)
  • ceil(source)
  • floor(source)
  • round_(source, precision=0)

pinepy.ta

Core indicators and helpers:

  • Moving averages: sma, ema, rma, wma, vwma
  • Volatility: stdev, variance, atr, true_range
  • Extremes: highest, lowest, highestbars, lowestbars
  • Momentum: rsi, roc, change
  • Aggregation: sum, cum
  • Price composites: hl2, hlc3, ohlc4
  • Crosses: cross, crossover, crossunder
  • Signal helpers: barssince / barslast, valuewhen

pinepy.array

  • Array with get, set, push, pop, size, clear
  • new_float, new_int, new_bool, new_string

pinepy.input

  • int, float, bool, string, source (all return defaults)

Examples

RSI + EMA signal

import pinepy as pine

close = df["close"]

ema_fast = pine.ta.ema(close, 12)
ema_slow = pine.ta.ema(close, 26)

long_signal = pine.ta.crossover(ema_fast, ema_slow)
short_signal = pine.ta.crossunder(ema_fast, ema_slow)

ATR-based stop

import pinepy as pine

high = df["high"]
low = df["low"]
close = df["close"]

atr_14 = pine.ta.atr(high, low, close, 14)
stop = close - 3 * atr_14

Value when

import pinepy as pine

cond = df["close"] > df["open"]
value = pine.ta.valuewhen(cond, df["close"], 0)

Compatibility notes

  • Outputs are pandas Series unless you pass pinepy.Series, in which case outputs are wrapped as pinepy.Series.
  • NA behavior follows pandas/numpy unless noted.
  • input.* functions are stubs.

Roadmap

Planned additions (incrementally, per request):

  • Expand ta to cover the full Pine v5 indicator set.
  • More Pine math functions and vectorized helpers.
  • Session/time helpers.
  • Plot/strategy stubs for API compatibility.

Contributing

If you want a specific Pine function, open an issue or request it directly.

Project details


Download files

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

Source Distribution

pine_script_py-0.1.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

pine_script_py-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pine_script_py-0.1.1.tar.gz.

File metadata

  • Download URL: pine_script_py-0.1.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pine_script_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 584d3b3494bf8c604db20d6fc82a0b8d08c05f9b92ffa2a52267eba0c04f51aa
MD5 9504585a09f59a6c9623869731812712
BLAKE2b-256 eb660d4c6f2aa7fce37a134e25e2c6c2ee90b8fe6c8f511dcf663fcb312a6fcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pine_script_py-0.1.1.tar.gz:

Publisher: publish.yml on Rishi-gupta-data/pine-script-py

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

File details

Details for the file pine_script_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pine_script_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pine_script_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5e66c35bac57c509b31c1fc049800abf872a5a52bb52b1ba2f005fbcd4094e1
MD5 580ef007f11220d0e0ebad068edc71f4
BLAKE2b-256 8228479aaf21f30631a7071c2829bdc4974fd03831da7dc25c0029aa81782f5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pine_script_py-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Rishi-gupta-data/pine-script-py

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page