Skip to main content

Plotly graph export library

Project description

Overview

Kaleido is a cross-platform Python library for generating static images (e.g. png, svg, pdf, etc.) for Plotly.js, to be used by Plotly.py.

Installation

Kaleido can be installed from PyPI using pip:

$ pip install kaleido --upgrade

As of version 1.0.0, Kaleido requires Chrome to be installed. If you already have Chrome on your system, Kaleido should find it; otherwise, you can install a compatible Chrome version using the kaleido_get_chrome command:

$ kaleido_get_chrome

or function in Python:

import kaleido
kaleido.get_chrome_sync()

Migrating from v0 to v1

Kaleido v1 introduces a new API. If you're currently using v0, you'll need to make changes to your code and environment where you are running Kaleido.

  • If using Kaleido v1 with Plotly.py, you will need to install Plotly.py v6.1.1 or later.
  • Chrome is no longer included with Kaleido. Kaleido will look for an existing Chrome installation, but also provides commands for installing Chrome. If you don't have Chrome, you'll need to install it. See the installation section above for instructions.
  • If your code uses Kaleido directly: kaleido.scopes.plotly has been removed in v1. Kaleido v1 provides write_fig and write_fig_sync for exporting Plotly figures.
from kaleido import write_fig_sync
import plotly.graph_objects as go

fig = go.Figure(data=[go.Scatter(y=[1, 3, 2])])
kaleido.write_fig_sync(fig, path="figure.png")

Development guide

Below are examples of how to use Kaleido directly in your Python program.

If you want to export images of Plotly charts, it's not necessary to call Kaleido directly; you can use functions in the Plotly library. See the Plotly documentation for instructions.

Usage examples

import kaleido

async with kaleido.Kaleido(n=4, timeout=90) as k:
  # n is number of processes
  await k.write_fig(fig, path="./", opts={"format":"jpg"})

# other `kaleido.Kaleido` arguments:
# page:  Change library version (see PageGenerators below)

# `Kaleido.write_fig()` arguments:
# - fig:       A single plotly figure or an iterable.
# - path:      A directory (names auto-generated based on title)
#              or a single file.
# - opts:      A dictionary with image options:
#              `{"scale":..., "format":..., "width":..., "height":...}`
# - error_log: If you pass a list here, image-generation errors will be appended
#              to the list and generation continues. If left as `None`, the
#              first error will cause failure.

# You can also use Kaleido.write_fig_from_object:
  await k.write_fig_from_object(fig_objects, error_log)
# where `fig_objects` is a dict to be expanded to the fig, path, opts arguments.

There are shortcut functions which can be used to generate images without creating a Kaleido() object:

import asyncio
import kaleido
asyncio.run(
  kaleido.write_fig(
    fig,
    path="./",
    n=4
  )
)

PageGenerators

The page argument takes a kaleido.PageGenerator() to customize versions. Normally, kaleido looks for an installed plotly as uses that version. You can pass kaleido.PageGenerator(force_cdn=True) to force use of a CDN version of plotly (the default if plotly is not installed).

my_page = kaleido.PageGenerator(
  plotly="A fully qualified link to plotly (https:// or file://)",
  mathjax=False # no mathjax, or another fully quality link
  others=["a list of other script links to include"]
)

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

kaleido-1.2.0.tar.gz (64.2 kB view details)

Uploaded Source

Built Distribution

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

kaleido-1.2.0-py3-none-any.whl (69.0 kB view details)

Uploaded Python 3

File details

Details for the file kaleido-1.2.0.tar.gz.

File metadata

  • Download URL: kaleido-1.2.0.tar.gz
  • Upload date:
  • Size: 64.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for kaleido-1.2.0.tar.gz
Algorithm Hash digest
SHA256 fa621a14423e8effa2895a2526be00af0cf21655be1b74b7e382c171d12e71ef
MD5 b2c725c8735c254053ea0722d7cd2fbd
BLAKE2b-256 38ad76eec859b71eda803a88ea50ed3f270281254656bb23d19eb0a39aa706a0

See more details on using hashes here.

File details

Details for the file kaleido-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: kaleido-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 69.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for kaleido-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c27ed82b51df6b923d0e656feac221343a0dbcd2fb9bc7e6b1db97f61e9a1513
MD5 ae4f819987a95a273521948a1db5ebb8
BLAKE2b-256 4b97f6de8d4af54d6401d6581a686cce3e3e2371a79ba459a449104e026c08bc

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