Skip to content

reporting#

Progress reporting and custom data/figures for generated reports.

add_figure #

add_figure(
    key: str,
    figure: Figure | ndarray | bytes | bytearray | str,
    dpi: int = 300,
    width: int | None = None,
    height: int | None = None,
) -> None

Render a figure (matplotlib/plotly/charts/PIL/numpy/PNG bytes) and embed it as {{custom.key}}.

clear_data #

clear_data(key: str | None = None) -> None

Clear the custom data for key, or all custom data if key is None.

figure_to_image #

figure_to_image(
    figure: Figure | ndarray | bytes | bytearray | str,
    dpi: int = 300,
    width: int | None = None,
    height: int | None = None,
) -> str

Render a figure to a data:image/png;base64,... URI and return it.

get_data #

get_data(key: str | None = None) -> object

Return the stored value for key, all custom data if key is None, or None if unset.

send_estimate #

send_estimate(
    duration: float | None = None,
    unit: Literal[
        "ns", "us", "ms", "s", "m", "h", "d"
    ] = "us",
    step: int | None = None,
    out_of: int | None = None,
) -> None

Send a time-remaining estimate to the frontend; no-op if duration is None.

set_data #

set_data(key: str, value: object) -> None

Store value under key, accessible in report templates as {{custom.key}}.

track_progress #

track_progress(
    iterable: Iterable[T],
    desc: str | None = None,
    total: int | None = None,
    initial_estimate: float | None = None,
    initial_estimate_unit: Literal[
        "ns", "us", "ms", "s", "m", "h", "d"
    ] = "s",
    unit: str = "it",
    disable: bool = False,
    report_estimates: bool = True,
) -> Iterator[T]

Wrap a loop to show a progress bar and live time-remaining estimate; also checks for cancellation.

for item in track_progress(range(100), desc="Processing"): ... ...