n-dimensional array viewer in Python with fast, interactive multi-dimensional image visualization
npx @tessl/cli install tessl/pypi-napari@0.6.0Napari is a fast, interactive, multi-dimensional image viewer for Python designed for browsing, annotating, and analyzing large multi-dimensional scientific images. Built on Qt for the GUI, vispy for performant GPU-based rendering, and the scientific Python stack, it provides a comprehensive platform for scientific image visualization and analysis with support for n-dimensional arrays, plugin architecture for extensibility, and integration with the broader scientific Python ecosystem.
pip install napariimport napariCommon patterns for direct access to specific functionality:
from napari import Viewer, view_image, view_labels
from napari.layers import Image, Labels, Points, Shapes
from napari.components import Dims, LayerListimport napari
import numpy as np
# Create sample image data
image_data = np.random.random((100, 100))
# Method 1: Create viewer then add layers
viewer = napari.Viewer()
viewer.add_image(image_data, name='Random Image')
# Method 2: Create viewer with image directly
viewer = napari.view_image(image_data, title='My Image Viewer')
# Show the viewer (starts Qt event loop)
napari.run()import napari
import numpy as np
# Create different types of data
image = np.random.random((100, 100))
labels = np.zeros((100, 100), dtype=int)
labels[25:75, 25:75] = 1
points = np.array([[50, 50], [25, 75]])
# Create viewer and add multiple layers
viewer = napari.Viewer()
viewer.add_image(image, name='Image')
viewer.add_labels(labels, name='Segmentation')
viewer.add_points(points, name='Points', size=10)
napari.run()Napari's architecture centers around a layered approach to multi-dimensional visualization:
This design enables napari to serve as both a standalone scientific image viewer and a platform for building domain-specific visualization applications in fields like microscopy, medical imaging, and scientific data analysis.
Main viewer class and viewer management functionality for creating and controlling napari viewers, including window management and viewer lifecycle.
class Viewer:
def __init__(self, *, title='napari', ndisplay=2, order=(), axis_labels=(), show=True, **kwargs): ...
def add_image(self, data, **kwargs): ...
def add_labels(self, data, **kwargs): ...
def add_points(self, data, **kwargs): ...
def add_shapes(self, data, **kwargs): ...
def add_surface(self, data, **kwargs): ...
def add_tracks(self, data, **kwargs): ...
def add_vectors(self, data, **kwargs): ...
def open(self, path, **kwargs): ...
def current_viewer(): ...
def run(*, force=False, gui_exceptions=False, max_loop_level=1): ...Complete set of layer types for visualizing different kinds of scientific data, from n-dimensional images to geometric annotations and measurements.
class Layer: ...
class Image(Layer): ...
class Labels(Layer): ...
class Points(Layer): ...
class Shapes(Layer): ...
class Surface(Layer): ...
class Tracks(Layer): ...
class Vectors(Layer): ...Core components that manage viewer state including dimensional navigation, camera controls, and layer management.
class Dims: ...
class Camera: ...
class LayerList: ...
class ViewerModel: ...Qt-based graphical user interface components, widgets, threading utilities, and event loop management for desktop applications.
class QtViewer: ...
class Window: ...
def get_qapp(): ...
def create_worker(func): ...
def thread_worker(func): ...Utility functions for colormaps, progress indicators, system information, notifications, and other helper functionality.
class Colormap: ...
def sys_info(): ...
def progress(iterable): ...
def progrange(n): ...Comprehensive type definitions for arrays, layer data, plugin interfaces, and configuration objects used throughout the napari ecosystem.
ArrayLike = Union[np.ndarray, 'dask.array.Array', 'zarr.Array']
LayerData = Union[tuple[Any], tuple[Any, Mapping], FullLayerData]
PathLike = Union[str, Path]
ReaderFunction = Callable[[PathOrPaths], list[LayerData]]Convenience functions for creating viewers with specific layer types:
# Create viewers with specific layer types
# NOTE: These view_* functions are deprecated as of napari 0.7.0
# Use Viewer().add_* methods instead
napari.view_image(data, **kwargs) -> napari.Viewer # Deprecated
napari.view_labels(data, **kwargs) -> napari.Viewer # Deprecated
napari.view_points(data, **kwargs) -> napari.Viewer # Deprecated
napari.view_shapes(data, **kwargs) -> napari.Viewer # Deprecated
napari.view_surface(data, **kwargs) -> napari.Viewer # Deprecated
napari.view_tracks(data, **kwargs) -> napari.Viewer # Deprecated
napari.view_vectors(data, **kwargs) -> napari.Viewer # Deprecated
napari.imshow(data, **kwargs) -> tuple[napari.Viewer, list[napari.layers.Image]] # matplotlib-style# Save layers using plugin system
napari.save_layers(path, layers, plugin=None)
# Access experimental features
from napari.experimental import link_layers, unlink_layers, layers_linked
def link_layers(layers, attributes=()) -> list:
"""Link attributes between all layers in layers."""
def unlink_layers(layers, attributes=()) -> None:
"""Unlink previously linked attributes between layers."""
def layers_linked(layers, attributes=()):
"""Context manager that temporarily links attributes on layers."""
# Access notification system
napari.notification_manager