Skip to main content

Generate multifunctional GUIs from classes

Project description

BSD 3-Clause License Python package index download statistics PyPI version Conda version


magic-class makes GUI development as easy as daily coding by converting well-typed Python class directly into GUI. It is powered by magicgui and has a smooth interface with napari. magic-class is also implemented with useful widgets such as matplotlib figure canvas, logger widget and color edit.

Target users

  • Researchers who already have their Python functions and classes and are planing to take a step forward to improve the interface using GUI, with minimum effort.
  • Non-professional programmers who don't want to spend time on debugging and maintaining GUI.
  • Users who are not satisfied with the low reproducibility of the most of the GUI.
  • People who are familiar with magicgui and interested in more sophisticated GUI using typing.

How magic-class solves your problems

  • Decorate your class with @magicclass and you are ready to use the class both in GUI and from console.
  • @magicclass implements macro-recorder in the class. You can easily create executable Python codes from the history of manual operations.
  • Your code looks almost "Pythonic". No need to be confused by messy class structure pecuilar to GUI development anymore.

magic-class is work in progress. Feel free to report issues, make suggestions and contribute!


Documentation is available here.


  • use pip
pip install magic-class -U
pip install magic-class[pyqt5] -U  # with pyqt5 backend
  • get the latest version
pip install git+


Let's make a simple GUI that can load 1-D data and plot it.

from magicclass import magicclass
from pathlib import Path

class PlotData:
    """Load 1D data and plot it."""

    def load(self, path: Path):
        Load file.

        path : Path
            File path
        """ = np.loadtxt(str(path))

    def plot(self):
        """Plot data."""

Classes decorated with @magicclass are converted to magicgui's Container widgets. GUI starts with show method.

ui = PlotData(title="Title")

You can continue analysis in console.


For people doing image analysis, it can be added to a napari viewer as a dock widget.

import napari
viewer = napari.Viewer()

Executable Python code (so called "macro" in many GUI tools) is available in macro attribute.

print(ui.macro)  # print macro  # open a text editor widget with macro written in

To make nicer GUI, you can also nest magic-class:

class PlotData:
    class Menu: ...

add a menubar with @magicmenu decorator:

class PlotData:
    class File: ...
    class Edit: ...

add context menu with @magiccontext decorator:

class PlotData:
    class contextmenu: ...
        def Copy(self): ...
        def Paste(self): ...

directly integrate magicgui and its widgets:

class PlotData:
    line = LineEdit()
    def load(self, path: Path): ...

... and so on.

Other examples are in the "examples" folder.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magic_class-0.7.10.tar.gz (206.9 kB view hashes)

Uploaded Source

Built Distribution

magic_class-0.7.10-py3-none-any.whl (271.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page