Layer Management¶
Functions for creating, modifying, and organizing layers in the napari viewer.
list_layers¶
Return a list of layers with key properties.
get_layer¶
async def get_layer(name: str, include_data: bool = False, slicing: str | None = None, max_elements: int | str = 1000) -> dict[str, Any]
Get detailed info about a layer, optionally including data.
Always returns metadata (shape, dtype, scale, translate, type-specific
properties). When include_data=True or slicing is provided,
also returns statistics and/or raw data values.
Parameters¶
name : str
Layer name (exact match).
include_data : bool, default False
If True, include data statistics (min/max/mean/std) and, for
small layers, inline data values.
slicing : str, optional
Numpy-style index string, e.g. "0, :5, :5". Implies
include_data=True.
max_elements : int, default 1000
Maximum number of data elements to return inline. Larger data
is stored and an output_id returned for read_output.
add_layer¶
async def add_layer(layer_type: str, path: str | None = None, data: list | None = None, data_var: str | None = None, name: str | None = None, colormap: str | None = None, blending: str | None = None, channel_axis: int | str | None = None, size: float | str | None = None, shape_type: str | None = None, edge_color: str | None = None, face_color: str | None = None, edge_width: float | str | None = None) -> dict[str, Any]
Add a layer to the viewer.
Parameters¶
layer_type : str
One of: "image", "labels", "points", "shapes",
"vectors", "tracks", "surface".
path : str, optional
File path (for image/labels).
data : list, optional
Inline data (coordinates, shape vertices, etc.).
data_var : str, optional
Name of a variable in the execute_code namespace.
name : str, optional
Layer name. Defaults to variable name or filename.
colormap : str, optional
Colormap name (image only).
blending : str, optional
Blending mode (image only).
channel_axis : int, optional
Channel axis (image only).
size : float, optional
Point size in pixels (points only, default 10).
shape_type : str, optional
Shape type: "rectangle", "ellipse", "line", "path", "polygon"
(shapes only, default "rectangle").
edge_color : str, optional
Edge color (shapes/vectors only).
face_color : str, optional
Face color (shapes only).
edge_width : float, optional
Edge width in pixels (shapes/vectors only).
remove_layer¶
Remove a layer by name.
set_layer_properties¶
async def set_layer_properties(name: str, visible: bool | None = None, opacity: float | None = None, colormap: str | None = None, blending: str | None = None, contrast_limits: list[float] | None = None, gamma: float | str | None = None, new_name: str | None = None, active: bool | None = None) -> dict[str, Any]
Set properties on a layer by name.
Parameters¶
name : str Layer name (exact match). visible, opacity, colormap, blending, contrast_limits, gamma Standard layer rendering properties. new_name : str, optional Rename the layer. active : bool, optional If True, make this the selected/active layer. Setting to False has no effect (use viewer selection directly).
reorder_layer¶
async def reorder_layer(name: str, index: int | str | None = None, before: str | None = None, after: str | None = None) -> dict[str, Any]
Reorder a layer by name.
Provide exactly one of: - index: absolute target index - before: move before this layer name - after: move after this layer name
apply_to_layers¶
async def apply_to_layers(filter_type: str | None = None, filter_pattern: str | None = None, properties: dict[str, Any] | None = None) -> dict[str, Any]
Apply property changes to multiple layers matching a filter.
Parameters¶
filter_type : str, optional
Layer type name to match (e.g., "Image", "Labels", "Points").
filter_pattern : str, optional
Glob pattern matched against layer names (e.g., "seg_*").
properties : dict, optional
Properties to set on matched layers. Supported keys: visible,
opacity, colormap, blending, contrast_limits,
gamma, new_name (renames by appending a suffix is NOT
supported — use set_layer_properties individually).
save_layer_data¶
Save a layer's data to a file.
Parameters¶
name : str
Layer name.
path : str
Output file path. Format is inferred from extension unless
format is specified. Supported: .tiff, .png,
.npy, .csv (points/tabular only).
format : str, optional
Explicit format override (e.g., "npy", "tiff").