Skip to main content

Lightweight Python wrapper for TradingView's lightweight-charts

Project description

PyPI license python

lwcharts

TradingView-quality interactive charts from pandas data, in one fluent chain.

chart = (
    Chart("BTC/USDT — 1D", theme="dark", height=700)
    .candles(df)
    .line(ema_20, name="EMA 20", color="#f0b429")
    .line(ema_50, name="EMA 50", color="#a5b4fc", style="dashed")
    .volume(df)
    .add_subplot(
        Subplot(height_ratio=0.2, label="RSI(14)", y_min=0, y_max=100)
        .line(rsi, color="#58a6ff")
        .hline(70, style="dashed")
        .hline(30, style="dashed")
    )
    .markers(entries, shape="arrowUp", position="belowBar", color="#26a641", label="E")
)
chart.serve()

Description

lwcharts is a simple python wrapper of the famous TradingView's Lightweight Charts

Why lwcharts

  • Zero JS knowledge required. You write pandas, you get interactive TradingView charts. Crosshair sync, scroll, zoom — all included.
  • Single createChart architecture. All subpanes share one time axis. No manual sync hacks, no drift between panes.
  • No calculation, no opinion. The lib renders what you give it. Your EMA, your RSI, your signals — computed with whatever tools you prefer.
  • Truly offline. The lightweight-charts JS bundle is embedded in the generated HTML by default. Works on air-gapped machines, in Jupyter.
  • Zero dependencies beyond pandas. No plotly, no bokeh, no nodejs, no webpack.

Installation

uv add lwcharts
# or
pip install lwcharts

Quickstart

import numpy as np
import pandas as pd
from lwcharts import Chart, Subplot

rng = np.random.default_rng(42)
n = 300
idx = pd.date_range("2023-01-01", periods=n, freq="B")
close = 42000 + np.cumsum(rng.normal(0, 500, n))
df = pd.DataFrame({
    "open":   close - rng.uniform(0, 300, n),
    "high":   close + rng.uniform(0, 600, n),
    "low":    close - rng.uniform(0, 600, n),
    "close":  close,
    "volume": rng.integers(500_000_000, 2_000_000_000, n).astype(float),
}, index=idx)

ema_20 = df["close"].ewm(span=20).mean()
ema_50 = df["close"].ewm(span=50).mean()
delta  = df["close"].diff()
rsi    = 100 - 100 / (1 + delta.clip(lower=0).ewm(com=13).mean()
                            / (-delta.clip(upper=0)).ewm(com=13).mean())

entries = pd.Series(False, index=idx)
entries.iloc[[40, 120, 210]] = True

chart = (
    Chart("BTC/USDT — 1D", theme="dark", height=700)
    .candles(df)
    .line(ema_20, name="EMA 20", color="#f0b429")
    .line(ema_50, name="EMA 50", color="#a5b4fc", style="dashed")
    .volume(df)
    .add_subplot(
        Subplot(height_ratio=0.2, label="RSI(14)", y_min=0, y_max=100)
        .line(rsi, color="#58a6ff")
        .hline(70, style="dashed")
        .hline(30, style="dashed")
    )
    .markers(entries, shape="arrowUp", position="belowBar", color="#26a641", label="E")
)
chart.serve()        # opens browser at localhost:1337
chart.to_html("btc.html")   # or write a self-contained HTML file

What the lib does not do

lwcharts is a rendering layer, not an analytics engine. It does not:

  • Calculate indicators (EMA, RSI, MACD, Bollinger…)
  • Fetch market data (no Bloomberg, CCXT, Yahoo Finance connectors)
  • Resample OHLCV (1D → 1W resampling belongs in pandas)

You keep full control of your data pipeline. Use pandas-ta, ta-lib, numpy, or your own in-house library to compute whatever you need, then pass the resulting Series directly to lwcharts.

Documentation

Full API reference, all methods, edge cases, and complete code examples: docs/DOCUMENTATION.md

License

MIT

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

lwcharts-0.3.0.tar.gz (78.2 kB view details)

Uploaded Source

Built Distribution

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

lwcharts-0.3.0-py3-none-any.whl (84.6 kB view details)

Uploaded Python 3

File details

Details for the file lwcharts-0.3.0.tar.gz.

File metadata

  • Download URL: lwcharts-0.3.0.tar.gz
  • Upload date:
  • Size: 78.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lwcharts-0.3.0.tar.gz
Algorithm Hash digest
SHA256 12e679de6b18490dc5f5128c497f4c979ac09005cc02f5edb1ade3a2b51cc6d3
MD5 1629ae29f02c587a2ea307a3644dff75
BLAKE2b-256 66879d5c500f39ebeb0488c5b1991ca76f2f73145cb9c2d740d6d3de52903b4f

See more details on using hashes here.

File details

Details for the file lwcharts-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lwcharts-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 84.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lwcharts-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0cde1dc847487e9fae62dc5a432250c9d41838c85b702108c23ee44697f067c4
MD5 0330d308e98bbf2339308b6a16e36831
BLAKE2b-256 91ae9b47a994c8a701c57d08629956a905c02ca9c78563a849a5318e81ad1773

See more details on using hashes here.

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