Skip to main content
v2.2

LightningChart and AI

Generating code with large language models (LLMs) is a rapidly growing area of interest for developers. While LLMs are often capable of generating working code it can be a challenge to consistently generate code for libraries like LightningChart Python that have several different versions and use cases.

This section is dedicated to hosting resources to help developers use AI tools with LightningChart Python better.

tip

Please share your own experiences with AI/LLM tools capability to work with LightningChart Python API at feedback.python@lightningchart.com

Guiding agentic work

In our experience LLM's are very poor at working with specific 3rd party libraries out of the box, because their training data is a mix of all the existing versions of that library. They also tend to hallucinate results by mixing data from various different libraries.

tip

The best results can be achieved by pointing your agents to use a specific set of LLM-friendly resources when thinking how to use PI.

For this purpose, we provide versions of our developer documentation and API reference in LLM friendly formats here:

  • Icpy-docs-llms.txt

  • Icpy-api-llms.txt

    Our recommendation is to download Icpy-docs-llms.txt and Icpy-api-llms.txt, place them in your project root and add following section(s) to your AGENTS.md or CLAUDE.md or equivalent:

  • You MUST always use the local files Icpy-docs-llms.txt and Icpy-api-llms.txt as the only sources of truth for all matters regarding how to use LightningChart Python library / lcpy

If in practice your agent attempts un-optimal approaches such as:

Then it is most likely a sign that you should tweak or alter your prompt and reattempt the command.

Guiding chat-based LLMs

Unfortunately, in our tests chat-based LLMs have much more trouble traversing specific documentations for reference compared to agents with local file access. You can try utilizing above materials also for chat-based LLMs, or a more basic approach which is to inject a minimal section of "common errors and what to do instead" right into the prompt, something like below:

You are an expert in LightningChart Python and Python application development. You write maintainable, performant, and accessible code following LightningChart Python best practices.


## LightningChart Python Best Practices

- Install LightningChart Python with `pip install lightningchart`. Requires Python 3.10 or higher.
- Always import the library with: `import lightningchart as lc`
- Always set your license key before creating charts: `lc.set_license('my-license-key')`
- Use the `add()` method for adding bulk data to series: `series.add(x=[0, 1, 2], y=[10, 15, 8])`
- Use `append_samples()` for real-time streaming data: `series.append_samples(x_values=[...], y_values=[...])`
- For progressive X data (auto-generated X values), use schema syntax:
series = chart.add_line_series(schema={'x': {'pattern': 'progressive'}})
- For real-time scrolling use cases, configure the axis like this:
axis_x = chart.get_default_x_axis()
axis_x.set_scroll_strategy(strategy='scrolling')
axis_x.set_interval(start=-100000, end=0, stop_axis_after=False)
chart.open(live=True)

- LightningChart Python has built-in data cleaning logic. Real-time applications can append data freely and control retention with `series.set_max_sample_count(max_sample_count=100, automatic=False)`
- Legends are enabled by default. chart.add_legend().add('series name') is an old removed API, do not use it.
- Cursors are enabled by default. Use `chart.set_cursor_mode("disabled")` to disable them.
- For real-time charts, use `chart.open(live=True)`.
- For static charts, use `chart.open()` without the live parameter.
- Always refer to API of latest library version. Latest documentation is found at https://lightningchart.com/python-charts/docs/ and https://lightningchart.com/python-charts/api-documentation/
- Verify all LightningChart Python API usage syntax from the latest documentation and from there only. Assume that your training data on LightningChart is out of date. Also don't look for references anywhere outside https://lightningchart.com/python-charts/
info

Maintaining a highly detailed rule set for LLMs is critical. This is because these models are trained on widespread resources that mainly consist of old, outdated materials, causing them to inherently be biased towards non-working syntax.

Please help us maintain an effective rule sheet by sharing what works best for you at feedback.python@lightningchart.com