From 53a8b1b81cff0685a577c24301c4ab905f89ec89 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Wed, 18 Jun 2025 15:46:04 -0400 Subject: [PATCH 1/4] update README for v1 release --- src/py/README.md | 71 +++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/src/py/README.md b/src/py/README.md index 6f28da29..7b238078 100644 --- a/src/py/README.md +++ b/src/py/README.md @@ -6,52 +6,52 @@ -# Pre-Launch Kaleido v1.0.0 - -Kaleido allows you to convert plotly figures to images. Kaleido v1 is currently available as a release candidate. - -## 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. - -- 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 following installation section for more details. -- `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") - ``` - See the Quickstart section below for more details on usage for v1. - -Note: Kaleido v1 works with Plotly v6.1.0 and later. +# 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 -To install the Kaleido release candidate: +Kaleido can be installed from [PyPI](https://pypi.org/project/kaleido) using `pip`: ```bash -$ pip install kaleido --upgrade --pre +$ pip install kaleido --upgrade ``` -To install Chrome, we recommend using Kaleido's CLI command: +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: ```bash $ kaleido_get_chrome ``` -or functions in Python: +or function in Python: ```python - import kaleido -await kaleido.get_chrome() -# or -# kaleido.get_chrome_sync() +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") ``` -## Quickstart +## 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.](https://plotly.com/python/static-image-export/) + +### Usage examples ```python import kaleido @@ -78,7 +78,7 @@ async with kaleido.Kaleido(n=4, timeout=90) as k: # where `fig_objects` is a dict to be expanded to the fig, path, opts arguments. ``` -There are shortcut functions if just want dont want to create a `Kaleido()`. +There are shortcut functions which can be used to generate images without creating a `Kaleido()` object: ```python import asyncio @@ -92,7 +92,7 @@ asyncio.run( ) ``` -## PageGenerators +### 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 @@ -106,12 +106,3 @@ my_page = kaleido.PageGenerator( ) ``` -## More info - -There are plenty of doc strings in the source code. - -[choreographer]: https://pypi.org/project/choreographer/ -[plotly]: https://plotly.com/ -[plotly-export]: https://plotly.com/python/static-image-export/ -[pypi]: https://pypi.org/ -[repo]: https://github.com/plotly/Kaleido From 695237ca956f57ee8a9b8c359c25bb9f00391bd6 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Wed, 18 Jun 2025 15:49:36 -0400 Subject: [PATCH 2/4] update changelog --- src/py/CHANGELOG.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/py/CHANGELOG.txt b/src/py/CHANGELOG.txt index 979bf42f..ab479456 100644 --- a/src/py/CHANGELOG.txt +++ b/src/py/CHANGELOG.txt @@ -1,4 +1,4 @@ -Unreleased +v1.0.0 - Add warning if using incompatible Plotly version v1.0.0rc15 From db4b2cd2f05246d55f6887d1d34b82d7877fda63 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Wed, 18 Jun 2025 15:58:59 -0400 Subject: [PATCH 3/4] linter --- src/py/kaleido/_mocker.py | 1 + src/py/kaleido/_page_generator.py | 1 + src/py/tests/test_calc_fig.py | 1 + 3 files changed, 3 insertions(+) diff --git a/src/py/kaleido/_mocker.py b/src/py/kaleido/_mocker.py index be10a66c..a7f49744 100644 --- a/src/py/kaleido/_mocker.py +++ b/src/py/kaleido/_mocker.py @@ -264,6 +264,7 @@ def build_mocks(): profiler = {} asyncio.run(_main(error_log, profiler)) finally: + # ruff: noqa: PLC0415 from operator import itemgetter for tab, tab_profile in profiler.items(): diff --git a/src/py/kaleido/_page_generator.py b/src/py/kaleido/_page_generator.py index 25d4e0b8..4925b8c9 100644 --- a/src/py/kaleido/_page_generator.py +++ b/src/py/kaleido/_page_generator.py @@ -59,6 +59,7 @@ def __init__(self, *, plotly=None, mathjax=None, others=None, force_cdn=False): plotly = (DEFAULT_PLOTLY, "utf-8") elif not plotly: try: + # ruff: noqa: PLC0415 import plotly as pltly # type: ignore [import-not-found] plotly_path = ( diff --git a/src/py/tests/test_calc_fig.py b/src/py/tests/test_calc_fig.py index 43afb9ce..70ae170f 100644 --- a/src/py/tests/test_calc_fig.py +++ b/src/py/tests/test_calc_fig.py @@ -12,6 +12,7 @@ async def test_calc_fig(): + # ruff: noqa: PLC0415 import plotly.express as px with warnings.catch_warnings(): From 0bd1b4703dbe965fa76c854f6d82960919be8ad9 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Thu, 19 Jun 2025 11:14:25 -0400 Subject: [PATCH 4/4] bump plotly min version in dev extra --- src/py/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/py/pyproject.toml b/src/py/pyproject.toml index 59547c95..de45a92b 100644 --- a/src/py/pyproject.toml +++ b/src/py/pyproject.toml @@ -48,7 +48,7 @@ dev = [ "async-timeout", "mypy>=1.14.1", "poethepoet>=0.30.0", - "plotly[express]>=6.0.0", + "plotly[express]>=6.1.1", "pytest-order>=1.3.0", "pandas>=2.0.3", ]