Kaleido Plot Export Library

1.2.0 · active · verified Thu Apr 09

Kaleido is a standalone library for generating static images (PNG, JPEG, SVG, PDF, EPS) from web-based visualizations, primarily designed for Plotly.py figures. It is currently at version 1.2.0 and receives updates for bug fixes and feature enhancements, with a significant API overhaul in v1.0.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the most common way to use Kaleido: through `plotly.io.write_image()` or directly on a `go.Figure` object. Kaleido is automatically detected and used by Plotly to render the static image. It highlights the importance of having a Chromium browser installed.

import plotly.graph_objects as go
import plotly.io as pio
import os

# Create a simple Plotly figure
fig = go.Figure(data=[go.Scatter(y=[1, 3, 2])])

# Most common way to use Kaleido: implicitly via plotly.io.write_image
output_file = "my_plot.png"
try:
    fig.write_image(output_file)
    print(f"Plot exported to {output_file}")
except ValueError as e:
    print(f"Error exporting plot: {e}")
    print("HINT: Ensure Kaleido is installed and a Chromium browser is available on your system or run `python -m kaleido.cli install`.")
    # Clean up dummy file if created by partial write
    if os.path.exists(output_file): os.remove(output_file)

# Example of using Kaleido's explicit sync server for performance (v1.1.0+)
# This is more advanced and not strictly needed for a single export.
# import kaleido
# try:
#     kaleido.start_sync_server()
#     fig.write_image("my_plot_sync.png")
#     print("Plot exported to my_plot_sync.png using sync server.")
# finally:
#     kaleido.stop_sync_server()

view raw JSON →