Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/py/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Unreleased
v1.0.0
- Add warning if using incompatible Plotly version

v1.0.0rc15
Expand Down
71 changes: 31 additions & 40 deletions src/py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@
</a>
</div>

# 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions src/py/kaleido/_mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions src/py/kaleido/_page_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion src/py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
1 change: 1 addition & 0 deletions src/py/tests/test_calc_fig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


async def test_calc_fig():
# ruff: noqa: PLC0415
import plotly.express as px

with warnings.catch_warnings():
Expand Down
Loading