Utilities¶
Advanced utility functions for screenshots, timelapse capture, code execution, package management, and output retrieval.
screenshot¶
async def screenshot(canvas_only: bool | str = True, save_path: str | None = None, axis: int | str | None = None, slice_range: str | None = None, interpolate_to_fit: bool = False, save_dir: str | None = None) -> ImageContent | list[ImageContent] | dict[str, Any]
Take a screenshot, or a timelapse series by sweeping a dims axis.
For a single screenshot, call with no axis/slice_range.
For a timelapse, provide both axis and slice_range.
Parameters¶
canvas_only : bool, default True
If True, only capture the canvas area.
save_path : str, optional
Save single screenshot to this file path (returns metadata).
axis : int, optional
Dims axis to sweep for timelapse (e.g., temporal axis).
slice_range : str, optional
Python-like slice string, e.g. "1:5", ":6", "::2".
Required when axis is provided.
interpolate_to_fit : bool, default False
If True, downsample timelapse frames to fit ~1.3 MB total.
save_dir : str, optional
Save timelapse frames as frame_NNNN.png in this directory.
execute_code¶
Execute arbitrary Python code in the server's interpreter.
Similar to napari's console. The execution namespace persists across calls and includes 'viewer', 'napari', and 'np'.
Parameters¶
code : str Python code string. The value of the last expression (if any) is returned as 'result_repr'. line_limit : int, default=30 Maximum number of output lines to return. Use -1 for unlimited output. Warning: Using -1 may consume a large number of tokens.
Note¶
In standalone mode, code execution runs synchronously on the main thread (required for Qt/napari operations) and has no timeout. In bridge mode, a 600-second timeout is enforced.
install_packages¶
async def install_packages(packages: list[str], upgrade: bool | None = False, no_deps: bool | None = False, index_url: str | None = None, extra_index_url: str | None = None, pre: bool | None = False, line_limit: int | str = 30, timeout: int = 240) -> dict[str, Any]
Install Python packages using pip.
Parameters¶
packages : list of str List of package specifiers (e.g., "scikit-image", "torch==2.3.1"). upgrade : bool, optional If True, pass --upgrade flag. no_deps : bool, optional If True, pass --no-deps flag. index_url : str, optional Custom index URL. extra_index_url : str, optional Extra index URL. pre : bool, optional Allow pre-releases (--pre flag). line_limit : int, default=30 Maximum number of output lines to return. Use -1 for unlimited output. timeout : int, default=240 Timeout for pip install in seconds.
read_output¶
Read stored tool output with optional line range.
Parameters¶
output_id : str Unique ID of the stored output. start : int, default=0 Starting line number (0-indexed). end : int, default=-1 Ending line number (exclusive). If -1, read to end.