{"id":13762313,"url":"https://github.com/louisnw01/lightweight-charts-python","last_synced_at":"2025-05-10T15:31:12.934Z","repository":{"id":163683553,"uuid":"639111479","full_name":"louisnw01/lightweight-charts-python","owner":"louisnw01","description":"Python framework for TradingView's Lightweight Charts JavaScript library.","archived":false,"fork":false,"pushed_at":"2024-03-30T17:42:11.000Z","size":21380,"stargazers_count":708,"open_issues_count":18,"forks_count":120,"subscribers_count":24,"default_branch":"main","last_synced_at":"2024-03-30T18:42:01.172Z","etag":null,"topics":["charting-library","financial-charting-library","live-charts","ohlc-chart","plotting","python","tradingview"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/louisnw01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"louisnw01","custom":"https://www.buymeacoffee.com/7wzcr2p9vxM/"}},"created_at":"2023-05-10T19:34:30.000Z","updated_at":"2024-04-14T16:43:57.808Z","dependencies_parsed_at":null,"dependency_job_id":"518277ee-f17e-443d-8f36-f7560762f120","html_url":"https://github.com/louisnw01/lightweight-charts-python","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisnw01%2Flightweight-charts-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisnw01%2Flightweight-charts-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisnw01%2Flightweight-charts-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louisnw01%2Flightweight-charts-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/louisnw01","download_url":"https://codeload.github.com/louisnw01/lightweight-charts-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224974208,"owners_count":17401100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charting-library","financial-charting-library","live-charts","ohlc-chart","plotting","python","tradingview"],"created_at":"2024-08-03T14:00:38.632Z","updated_at":"2024-11-16T21:30:21.420Z","avatar_url":"https://github.com/louisnw01.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n\n# lightweight-charts-python\n\n[![PyPi Release](https://img.shields.io/pypi/v/lightweight-charts?color=32a852\u0026label=PyPi)](https://pypi.org/project/lightweight-charts/)\n[![Made with Python](https://img.shields.io/badge/Python-3.8+-c7a002?logo=python\u0026logoColor=white)](https://python.org \"Go to Python homepage\")\n[![License](https://img.shields.io/github/license/louisnw01/lightweight-charts-python?color=9c2400)](https://github.com/louisnw01/lightweight-charts-python/blob/main/LICENSE)\n[![Documentation](https://img.shields.io/badge/documentation-006ee3)](https://lightweight-charts-python.readthedocs.io/en/latest/index.html)\n\n![cover](https://raw.githubusercontent.com/louisnw01/lightweight-charts-python/main/cover.png)\n\nlightweight-charts-python aims to provide a simple and pythonic way to access and implement [TradingView's Lightweight Charts](https://www.tradingview.com/lightweight-charts/).\n\u003c/div\u003e\n\n\n## Installation\n```\npip install lightweight-charts\n```\n___\n\n## Features\n1. Streamlined for live data, with methods for updating directly from tick data.\n2. Multi-pane charts using [Subcharts](https://lightweight-charts-python.readthedocs.io/en/latest/reference/abstract_chart.html#AbstractChart.create_subchart).\n3. The [Toolbox](https://lightweight-charts-python.readthedocs.io/en/latest/reference/toolbox.html), allowing for trendlines, rectangles, rays and horizontal lines to be drawn directly onto charts.\n4. [Events](https://lightweight-charts-python.readthedocs.io/en/latest/tutorials/events.html) allowing for timeframe selectors (1min, 5min, 30min etc.), searching, hotkeys, and more.\n5. [Tables](https://lightweight-charts-python.readthedocs.io/en/latest/reference/tables.html) for watchlists, order entry, and trade management.\n6. Direct integration of market data through [Polygon.io's](https://polygon.io/?utm_source=affiliate\u0026utm_campaign=pythonlwcharts) market data API.\n\n__Supports:__ Jupyter Notebooks, PyQt6, PyQt5, PySide6, wxPython, Streamlit, and asyncio.\n\nPartTimeLarry: [Interactive Brokers API and TradingView Charts in Python](https://www.youtube.com/watch?v=TlhDI3PforA)\n___\n\n### 1. Display data from a csv:\n\n```python\nimport pandas as pd\nfrom lightweight_charts import Chart\n\n\nif __name__ == '__main__':\n    \n    chart = Chart()\n    \n    # Columns: time | open | high | low | close | volume \n    df = pd.read_csv('ohlcv.csv')\n    chart.set(df)\n    \n    chart.show(block=True)\n\n```\n![setting_data image](https://raw.githubusercontent.com/louisnw01/lightweight-charts-python/main/examples/1_setting_data/setting_data.png)\n___\n\n### 2. Updating bars in real-time:\n\n```python\nimport pandas as pd\nfrom time import sleep\nfrom lightweight_charts import Chart\n\nif __name__ == '__main__':\n\n    chart = Chart()\n\n    df1 = pd.read_csv('ohlcv.csv')\n    df2 = pd.read_csv('next_ohlcv.csv')\n\n    chart.set(df1)\n\n    chart.show()\n\n    last_close = df1.iloc[-1]['close']\n    \n    for i, series in df2.iterrows():\n        chart.update(series)\n\n        if series['close'] \u003e 20 and last_close \u003c 20:\n            chart.marker(text='The price crossed $20!')\n            \n        last_close = series['close']\n        sleep(0.1)\n\n```\n\n![live data gif](https://github.com/louisnw01/lightweight-charts-python/blob/main/examples/2_live_data/live_data.gif?raw=true)\n___\n\n### 3. Updating bars from tick data in real-time:\n\n```python\nimport pandas as pd\nfrom time import sleep\nfrom lightweight_charts import Chart\n\n\nif __name__ == '__main__':\n    \n    df1 = pd.read_csv('ohlc.csv')\n    \n    # Columns: time | price \n    df2 = pd.read_csv('ticks.csv')\n    \n    chart = Chart()\n    \n    chart.set(df1)\n    \n    chart.show()\n    \n    for i, tick in df2.iterrows():\n        chart.update_from_tick(tick)\n            \n        sleep(0.03)\n\n```\n![tick data gif](https://raw.githubusercontent.com/louisnw01/lightweight-charts-python/main/examples/3_tick_data/tick_data.gif)\n___\n\n### 4. Line Indicators:\n\n```python\nimport pandas as pd\nfrom lightweight_charts import Chart\n\n\ndef calculate_sma(df, period: int = 50):\n    return pd.DataFrame({\n        'time': df['date'],\n        f'SMA {period}': df['close'].rolling(window=period).mean()\n    }).dropna()\n\n\nif __name__ == '__main__':\n    chart = Chart()\n    chart.legend(visible=True)\n\n    df = pd.read_csv('ohlcv.csv')\n    chart.set(df)\n\n    line = chart.create_line('SMA 50')\n    sma_data = calculate_sma(df, period=50)\n    line.set(sma_data)\n\n    chart.show(block=True)\n\n```\n![line indicators image](https://raw.githubusercontent.com/louisnw01/lightweight-charts-python/main/examples/4_line_indicators/line_indicators.png)\n___\n\n### 5. Styling:\n\n```python\nimport pandas as pd\nfrom lightweight_charts import Chart\n\n\nif __name__ == '__main__':\n    \n    chart = Chart()\n\n    df = pd.read_csv('ohlcv.csv')\n\n    chart.layout(background_color='#090008', text_color='#FFFFFF', font_size=16,\n                 font_family='Helvetica')\n\n    chart.candle_style(up_color='#00ff55', down_color='#ed4807',\n                       border_up_color='#FFFFFF', border_down_color='#FFFFFF',\n                       wick_up_color='#FFFFFF', wick_down_color='#FFFFFF')\n\n    chart.volume_config(up_color='#00ff55', down_color='#ed4807')\n\n    chart.watermark('1D', color='rgba(180, 180, 240, 0.7)')\n\n    chart.crosshair(mode='normal', vert_color='#FFFFFF', vert_style='dotted',\n                    horz_color='#FFFFFF', horz_style='dotted')\n\n    chart.legend(visible=True, font_size=14)\n\n    chart.set(df)\n\n    chart.show(block=True)\n\n```\n![styling image](https://raw.githubusercontent.com/louisnw01/lightweight-charts-python/main/examples/5_styling/styling.png)\n___\n\n### 6. Callbacks:\n\n```python\nimport pandas as pd\nfrom lightweight_charts import Chart\n\n\ndef get_bar_data(symbol, timeframe):\n    if symbol not in ('AAPL', 'GOOGL', 'TSLA'):\n        print(f'No data for \"{symbol}\"')\n        return pd.DataFrame()\n    return pd.read_csv(f'bar_data/{symbol}_{timeframe}.csv')\n\n\ndef on_search(chart, searched_string):  # Called when the user searches.\n    new_data = get_bar_data(searched_string, chart.topbar['timeframe'].value)\n    if new_data.empty:\n        return\n    chart.topbar['symbol'].set(searched_string)\n    chart.set(new_data)\n\n\ndef on_timeframe_selection(chart):  # Called when the user changes the timeframe.\n    new_data = get_bar_data(chart.topbar['symbol'].value, chart.topbar['timeframe'].value)\n    if new_data.empty:\n        return\n    chart.set(new_data, True)\n\n\ndef on_horizontal_line_move(chart, line):\n    print(f'Horizontal line moved to: {line.price}')\n\n\nif __name__ == '__main__':\n    chart = Chart(toolbox=True)\n    chart.legend(True)\n\n    chart.events.search += on_search\n\n    chart.topbar.textbox('symbol', 'TSLA')\n    chart.topbar.switcher('timeframe', ('1min', '5min', '30min'), default='5min',\n                          func=on_timeframe_selection)\n\n    df = get_bar_data('TSLA', '5min')\n    chart.set(df)\n\n    chart.horizontal_line(200, func=on_horizontal_line_move)\n\n    chart.show(block=True)\n\n```\n![callbacks gif](https://raw.githubusercontent.com/louisnw01/lightweight-charts-python/main/examples/6_callbacks/callbacks.gif)\n___\n\n\u003cdiv align=\"center\"\u003e\n\n[![Documentation](https://img.shields.io/badge/documentation-006ee3)](https://lightweight-charts-python.readthedocs.io/en/latest/index.html)\n\nInquiries: [shaders_worker_0e@icloud.com](mailto:shaders_worker_0e@icloud.com)\n___\n\n_This package is an independent creation and has not been endorsed, sponsored, or approved by TradingView. The author of this package does not have any official relationship with TradingView, and the package does not represent the views or opinions of TradingView._\n\u003c/div\u003e\n","funding_links":["https://github.com/sponsors/louisnw01","https://www.buymeacoffee.com/7wzcr2p9vxM/"],"categories":["Community","TypeScript"],"sub_categories":["Lightweight Charts™","Lightweight Charts"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisnw01%2Flightweight-charts-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flouisnw01%2Flightweight-charts-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouisnw01%2Flightweight-charts-python/lists"}