Skip to content

Commit 7702233

Browse files
authored
Merge pull request #5062 from plotly/upgrade-kaleido
Support Kaleido v1 in Plotly.py
2 parents ab3fbbd + 0c1b1c1 commit 7702233

File tree

11 files changed

+938
-260
lines changed

11 files changed

+938
-260
lines changed

.circleci/config.yml

+45
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,35 @@ commands:
114114
source .venv/bin/activate
115115
python -m pytest -x test_init/test_lazy_imports.py
116116
117+
test_io_kaleido_v0:
118+
steps:
119+
- checkout
120+
- browser-tools/install-chrome
121+
- browser-tools/install-chromedriver
122+
- run:
123+
name: Install dependencies
124+
command: |
125+
curl -LsSf https://astral.sh/uv/install.sh | sh
126+
uv venv
127+
source .venv/bin/activate
128+
uv pip install .
129+
uv pip install -r ./test_requirements/requirements_optional.txt
130+
# Install Kaleido v0 instead of the v1 specified in requirements_optional.txt
131+
uv pip uninstall kaleido
132+
uv pip install kaleido==0.2.1
133+
- run:
134+
name: List installed packages and python version
135+
command: |
136+
source .venv/bin/activate
137+
uv pip list
138+
python --version
139+
- run:
140+
name: Test plotly.io image output with Kaleido v0
141+
command: |
142+
source .venv/bin/activate
143+
python -m pytest tests/test_optional/test_kaleido
144+
no_output_timeout: 20m
145+
117146
jobs:
118147
check-code-formatting:
119148
docker:
@@ -163,6 +192,17 @@ jobs:
163192
pandas_version: <<parameters.pandas_version>>
164193
numpy_version: <<parameters.numpy_version>>
165194

195+
test_kaleido_v0:
196+
parameters:
197+
python_version:
198+
default: "3.12"
199+
type: string
200+
executor:
201+
name: docker-container
202+
python_version: <<parameters.python_version>>
203+
steps:
204+
- test_io_kaleido_v0
205+
166206
# Percy
167207
python_311_percy:
168208
docker:
@@ -435,5 +475,10 @@ workflows:
435475
python_version: "3.9"
436476
pandas_version: "1.2.4"
437477
numpy_version: "1.26.4"
478+
- test_kaleido_v0:
479+
matrix:
480+
parameters:
481+
python_version:
482+
- "3.12"
438483
- python_311_percy
439484
- build-doc

CHANGELOG.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## Unreleased
5+
## [6.1.0b0] - 2025-03-31
6+
7+
### Updated
8+
- Add support for Kaleido >= v1.0.0 for image generation, and deprecate support for Kaleido<1 and Orca [[#5062](https://github.com/plotly/plotly.py/pull/5062)]
69

710
### Fixed
8-
- Fix third-party widget display issues in v6 [[#5102]https://github.com/plotly/plotly.py/pull/5102]
11+
- Fix third-party widget display issues in v6 [[#5102](https://github.com/plotly/plotly.py/pull/5102)]
12+
- Add handling for case where `jupyterlab` or `notebook` is not installed [[#5104](https://github.com/plotly/plotly.py/pull/5104/files)]
13+
- Fix issue causing Plotly.js script to be embedded multiple times in Jupyter notebooks [[#5112](https://github.com/plotly/plotly.py/pull/5112)]
914

1015
## [6.0.1] - 2025-03-14
1116

plotly/basedatatypes.py

+78-20
Original file line numberDiff line numberDiff line change
@@ -3740,48 +3740,77 @@ def to_image(self, *args, **kwargs):
37403740
- 'webp'
37413741
- 'svg'
37423742
- 'pdf'
3743-
- 'eps' (Requires the poppler library to be installed)
3743+
- 'eps' (deprecated) (Requires the poppler library to be installed)
37443744
3745-
If not specified, will default to `plotly.io.config.default_format`
3745+
If not specified, will default to:
3746+
- `plotly.io.defaults.default_format` if engine is "kaleido"
3747+
- `plotly.io.orca.config.default_format` if engine is "orca" (deprecated)
37463748
37473749
width: int or None
37483750
The width of the exported image in layout pixels. If the `scale`
37493751
property is 1.0, this will also be the width of the exported image
37503752
in physical pixels.
37513753
3752-
If not specified, will default to `plotly.io.config.default_width`
3754+
If not specified, will default to:
3755+
- `plotly.io.defaults.default_width` if engine is "kaleido"
3756+
- `plotly.io.orca.config.default_width` if engine is "orca" (deprecated)
37533757
37543758
height: int or None
37553759
The height of the exported image in layout pixels. If the `scale`
37563760
property is 1.0, this will also be the height of the exported image
37573761
in physical pixels.
37583762
3759-
If not specified, will default to `plotly.io.config.default_height`
3763+
If not specified, will default to:
3764+
- `plotly.io.defaults.default_height` if engine is "kaleido"
3765+
- `plotly.io.orca.config.default_height` if engine is "orca" (deprecated)
37603766
37613767
scale: int or float or None
37623768
The scale factor to use when exporting the figure. A scale factor
37633769
larger than 1.0 will increase the image resolution with respect
37643770
to the figure's layout pixel dimensions. Whereas as scale factor of
37653771
less than 1.0 will decrease the image resolution.
37663772
3767-
If not specified, will default to `plotly.io.config.default_scale`
3773+
If not specified, will default to:
3774+
- `plotly.io.defaults.default_scale` if engine is "kaliedo"
3775+
- `plotly.io.orca.config.default_scale` if engine is "orca" (deprecated)
37683776
37693777
validate: bool
37703778
True if the figure should be validated before being converted to
37713779
an image, False otherwise.
37723780
3773-
engine: str
3774-
Image export engine to use:
3775-
- "kaleido": Use Kaleido for image export
3776-
- "orca": Use Orca for image export
3777-
- "auto" (default): Use Kaleido if installed, otherwise use orca
3781+
engine (deprecated): str
3782+
Image export engine to use. This parameter is deprecated and Orca engine support will be
3783+
dropped in the next major Plotly version. Until then, the following values are supported:
3784+
- "kaleido": Use Kaleido for image export
3785+
- "orca": Use Orca for image export
3786+
- "auto" (default): Use Kaleido if installed, otherwise use Orca
37783787
37793788
Returns
37803789
-------
37813790
bytes
37823791
The image data
37833792
"""
37843793
import plotly.io as pio
3794+
from plotly.io.kaleido import (
3795+
kaleido_available,
3796+
kaleido_major,
3797+
KALEIDO_DEPRECATION_MSG,
3798+
ORCA_DEPRECATION_MSG,
3799+
ENGINE_PARAM_DEPRECATION_MSG,
3800+
)
3801+
3802+
if (
3803+
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3804+
and kaleido_available()
3805+
and kaleido_major() < 1
3806+
):
3807+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3808+
if kwargs.get("engine", None) == "orca":
3809+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3810+
if kwargs.get("engine", None):
3811+
warnings.warn(
3812+
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3813+
)
37853814

37863815
return pio.to_image(self, *args, **kwargs)
37873816

@@ -3803,49 +3832,78 @@ def write_image(self, *args, **kwargs):
38033832
- 'webp'
38043833
- 'svg'
38053834
- 'pdf'
3806-
- 'eps' (Requires the poppler library to be installed)
3835+
- 'eps' (deprecated) (Requires the poppler library to be installed)
38073836
38083837
If not specified and `file` is a string then this will default to the
38093838
file extension. If not specified and `file` is not a string then this
3810-
will default to `plotly.io.config.default_format`
3839+
will default to:
3840+
- `plotly.io.defaults.default_format` if engine is "kaleido"
3841+
- `plotly.io.orca.config.default_format` if engine is "orca" (deprecated)
38113842
38123843
width: int or None
38133844
The width of the exported image in layout pixels. If the `scale`
38143845
property is 1.0, this will also be the width of the exported image
38153846
in physical pixels.
38163847
3817-
If not specified, will default to `plotly.io.config.default_width`
3848+
If not specified, will default to:
3849+
- `plotly.io.defaults.default_width` if engine is "kaleido"
3850+
- `plotly.io.orca.config.default_width` if engine is "orca" (deprecated)
38183851
38193852
height: int or None
38203853
The height of the exported image in layout pixels. If the `scale`
38213854
property is 1.0, this will also be the height of the exported image
38223855
in physical pixels.
38233856
3824-
If not specified, will default to `plotly.io.config.default_height`
3857+
If not specified, will default to:
3858+
- `plotly.io.defaults.default_height` if engine is "kaleido"
3859+
- `plotly.io.orca.config.default_height` if engine is "orca" (deprecated)
38253860
38263861
scale: int or float or None
38273862
The scale factor to use when exporting the figure. A scale factor
38283863
larger than 1.0 will increase the image resolution with respect
38293864
to the figure's layout pixel dimensions. Whereas as scale factor of
38303865
less than 1.0 will decrease the image resolution.
38313866
3832-
If not specified, will default to `plotly.io.config.default_scale`
3867+
If not specified, will default to:
3868+
- `plotly.io.defaults.default_scale` if engine is "kaleido"
3869+
- `plotly.io.orca.config.default_scale` if engine is "orca" (deprecated)
38333870
38343871
validate: bool
38353872
True if the figure should be validated before being converted to
38363873
an image, False otherwise.
38373874
3838-
engine: str
3839-
Image export engine to use:
3840-
- "kaleido": Use Kaleido for image export
3841-
- "orca": Use Orca for image export
3842-
- "auto" (default): Use Kaleido if installed, otherwise use orca
3875+
engine (deprecated): str
3876+
Image export engine to use. This parameter is deprecated and Orca engine support will be
3877+
dropped in the next major Plotly version. Until then, the following values are supported:
3878+
- "kaleido": Use Kaleido for image export
3879+
- "orca": Use Orca for image export
3880+
- "auto" (default): Use Kaleido if installed, otherwise use Orca
3881+
38433882
Returns
38443883
-------
38453884
None
38463885
"""
38473886
import plotly.io as pio
3887+
from plotly.io.kaleido import (
3888+
kaleido_available,
3889+
kaleido_major,
3890+
KALEIDO_DEPRECATION_MSG,
3891+
ORCA_DEPRECATION_MSG,
3892+
ENGINE_PARAM_DEPRECATION_MSG,
3893+
)
38483894

3895+
if (
3896+
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3897+
and kaleido_available()
3898+
and kaleido_major() < 1
3899+
):
3900+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3901+
if kwargs.get("engine", None) == "orca":
3902+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3903+
if kwargs.get("engine", None):
3904+
warnings.warn(
3905+
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3906+
)
38493907
return pio.write_image(self, *args, **kwargs)
38503908

38513909
# Static helpers

plotly/io/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33
from typing import TYPE_CHECKING
44

55
if sys.version_info < (3, 7) or TYPE_CHECKING:
6-
from ._kaleido import to_image, write_image, full_figure_for_development
6+
from ._kaleido import (
7+
to_image,
8+
write_image,
9+
write_images,
10+
full_figure_for_development,
11+
)
712
from . import orca, kaleido
813
from . import json
914
from ._json import to_json, from_json, read_json, write_json
1015
from ._templates import templates, to_templated
1116
from ._html import to_html, write_html
1217
from ._renderers import renderers, show
1318
from . import base_renderers
19+
from ._kaleido import defaults
1420

1521
__all__ = [
1622
"to_image",
1723
"write_image",
24+
"write_images",
1825
"orca",
1926
"json",
2027
"to_json",
@@ -29,6 +36,7 @@
2936
"show",
3037
"base_renderers",
3138
"full_figure_for_development",
39+
"defaults",
3240
]
3341
else:
3442
__all__, __getattr__, __dir__ = relative_import(
@@ -37,6 +45,7 @@
3745
[
3846
"._kaleido.to_image",
3947
"._kaleido.write_image",
48+
"._kaleido.write_images",
4049
"._kaleido.full_figure_for_development",
4150
"._json.to_json",
4251
"._json.from_json",
@@ -48,6 +57,7 @@
4857
"._html.write_html",
4958
"._renderers.renderers",
5059
"._renderers.show",
60+
"._kaleido.defaults",
5161
],
5262
)
5363

plotly/io/_defaults.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Default settings for image generation
2+
3+
4+
class _Defaults(object):
5+
"""
6+
Class to store default settings for image generation.
7+
"""
8+
9+
def __init__(self):
10+
self.default_format = "png"
11+
self.default_width = 700
12+
self.default_height = 500
13+
self.default_scale = 1
14+
self.mathjax = None
15+
self.topojson = None
16+
17+
18+
defaults = _Defaults()

0 commit comments

Comments
 (0)