Skip to content

armeya25/lwc-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

if on i3/swaywm windows manager

export WEBKIT_DISABLE_COMPOSITING_MODE="1" add this to .bashrc file

notes

some examples in examples/ you cant directly run those examples from that directory. you need to move it to the root directory and run it from there.

screenshots

single chart multi chart indicator example drawing tools

lwc-python

lwc-python is a Python charting library that provides a high-performance, interactive, and beautifully styled charting interface by bridging Python and TradingView's Lightweight Charts via pywebview.

Features

  • High Performance: Uses polars for fast data processing and multiprocessing to run the GUI in a separate process, preventing the main Python thread from blocking.
  • Interactive UI: Supports crosshair synchronization, custom grid layouts (e.g., single, 2x1, 1x2, 2x2), and interactive floating tooltips.
  • Auto Volume Histograms: Automatically adds a colored volume histogram if the provided DataFrame contains a volume column.
  • Drawing Tools: Includes tools for adding lines, markers, boxes, and position widgets directly from Python.

Example Usage

from lwc.chart import Chart
import polars as pl

if __name__ == '__main__':
    chart = Chart()

    # Create layout and get chart instances
    layout = chart.set_layout('single')
    
    # Create a candlestick series
    ch1 = layout[0].create_candlestick_series("Main Chart")

    # Load data into a Polars DataFrame
    df = pl.read_csv("1d.csv")
    
    # Set data (auto-detects 'volume' column and adds histogram)
    ch1.set_data(df)
    
    # Show the chart blocking
    chart.show(block=True)

Drawing Tools Example

from lwc.chart import Chart
import polars as pl

if __name__ == '__main__':
    chart = Chart()
    layout = chart.set_layout()
    ch1 = layout[0].create_candlestick_series("Main Chart")

    df = pl.read_csv("1d.csv")
    df = df.with_columns(pl.col("date").cast(pl.Datetime("ms")))
    ch1.set_data(df)

    # 1. Horizontal Line (PriceLine)
    layout[0].toolbox.create_horizontal_line(series_id=ch1.series_id, price=18.5, color='#F44336', text='Support')
    
    # 2. Box / Rectangle
    layout[0].toolbox.create_box(
        start_time=df['date'][5], 
        end_time=df['date'][15], 
        start_price=19.5, 
        end_price=17.0, 
        color='rgba(255, 255, 0, 0.2)', 
        border_color='#d4af37', 
        text='Consolidation'
    )

    # See examples/drawing tools.py for more examples like trendlines, fib retracement, and markers.

    chart.show(block=True)

Project Structure

  • lwc/: The Python backend wrapper logic.
  • frontend/lwc/: The web interface containing HTML, CSS, and JS logic tying the Lightweight Charts library to the python backend.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors