napari-console

A plugin that adds a console to napari

  • napari team

License PyPI Python Version tests codecov

A plugin that adds a console to napari


This napari plugin was generated with Cookiecutter using with @napari's cookiecutter-napari-plugin template.

Local variables

In napari-console 0.0.8 and earlier, the console locals() namespace only contained a reference to the napari viewer that enclosed the console.

Since version 0.0.9, it instead contains everything in the enclosing frame that called napari. That is, if your Python code is:

import napari
import numpy as np
from scipy import ndimage as ndi

image = np.random.random((500, 500))
labels = ndi.label(image > 0.7)[0]

viewer, image_layer = napari.imshow(image)
labels_layer = viewer.add_labels(labels)

napari.run()

Then the napari console will have the variables np, napari, ndi, image, labels, viewer, image_layer, and labels_layer in its namespace.

This is implemented by inspecting the Python stack when the console is first instantiated, finding the first frame that is outside of the napari_console, napari, and in_n_out modules, and passing the variables in the frame's f_locals and f_globals to the console namespace.

If you want to disable this behavior (for example, because you are embedding napari and the console within some larger application), you can add NAPARI_EMBED=1 to your environment variables before instantiating the console.

Installation

You can install napari-console via pip:

pip install napari-console

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the BSD-3 license, "napari-console" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Version:

  • 0.1.3

Last updated:

  • 2024-12-20

First released:

  • 2021-01-21

License:

  • BSD-3-Clause

Supported data:

  • Information not submitted

Plugin type:

Open extension:

Save extension:

Python versions supported:

Operating system:

  • Information not submitted

Requirements:

  • IPython>=7.7.0
  • ipykernel>=5.2.0
  • qtconsole!=4.7.6,!=5.4.2,>=4.5.1
  • qtpy>=1.7.0
  • PySide2!=5.15.0,>=5.13.2; (python_version < "3.11" and platform_machine != "arm64") and extra == "pyside2"
  • PySide6<6.5; python_version < "3.12" and extra == "pyside6-experimental"
  • PyQt6>6.5; extra == "pyqt6"
  • PyQt6!=6.6.1; platform_system == "Darwin" and extra == "pyqt6"
  • napari-console[pyside2]; extra == "pyside"
  • PyQt5!=5.15.0,>=5.13.2; extra == "pyqt5"
  • napari-console[pyqt5]; extra == "pyqt"
  • napari-console[pyqt]; extra == "qt"
  • napari[pyqt]; extra == "testing"
Website by the napari team, original design by CZI. Go to napari main website.