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.naisnumpy.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 bylength.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
Arraywithget,set,push,pop,size,clearnew_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 aspinepy.Series. - NA behavior follows pandas/numpy unless noted.
input.*functions are stubs.
Roadmap
Planned additions (incrementally, per request):
- Expand
tato 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
584d3b3494bf8c604db20d6fc82a0b8d08c05f9b92ffa2a52267eba0c04f51aa
|
|
| MD5 |
9504585a09f59a6c9623869731812712
|
|
| BLAKE2b-256 |
eb660d4c6f2aa7fce37a134e25e2c6c2ee90b8fe6c8f511dcf663fcb312a6fcf
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pine_script_py-0.1.1.tar.gz -
Subject digest:
584d3b3494bf8c604db20d6fc82a0b8d08c05f9b92ffa2a52267eba0c04f51aa - Sigstore transparency entry: 926876837
- Sigstore integration time:
-
Permalink:
Rishi-gupta-data/pine-script-py@2d92851e8f3c76ee7239680c77c4962ce70e5c77 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Rishi-gupta-data
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d92851e8f3c76ee7239680c77c4962ce70e5c77 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5e66c35bac57c509b31c1fc049800abf872a5a52bb52b1ba2f005fbcd4094e1
|
|
| MD5 |
580ef007f11220d0e0ebad068edc71f4
|
|
| BLAKE2b-256 |
8228479aaf21f30631a7071c2829bdc4974fd03831da7dc25c0029aa81782f5b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pine_script_py-0.1.1-py3-none-any.whl -
Subject digest:
c5e66c35bac57c509b31c1fc049800abf872a5a52bb52b1ba2f005fbcd4094e1 - Sigstore transparency entry: 926876840
- Sigstore integration time:
-
Permalink:
Rishi-gupta-data/pine-script-py@2d92851e8f3c76ee7239680c77c4962ce70e5c77 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Rishi-gupta-data
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d92851e8f3c76ee7239680c77c4962ce70e5c77 -
Trigger Event:
workflow_dispatch
-
Statement type: