Skip to content

Overview#

Psygnal (pronounced "signal") is a pure python implementation of Qt-style Signals with (optional) signature and type checking, and support for threading.

Important

This library does not require or use Qt in any way. It simply implements the observer pattern: inter-object communication with loose coupling.

Performance is a high priority, as signals are often emitted frequently, benchmarks are routinely measured. Code is compiled using mypyc.

Tip

To run psygnal without using the compiled code, set an PSYGNAL_UNCOMPILED environment variable to 1. (You can also just delete the .so files in the psygnal folder).

Quickstart#

A very simple example:

# import psygnal.Signal
from psygnal import Signal

class MyObject:
    # define one or signals as class attributes
    value_changed = Signal(str)
    shutting_down = Signal()

# create an instance
my_obj = MyObject()

# You (or others) can connect callbacks to your signals
@my_obj.value_changed.connect
def on_change(new_value: str):
    print(f"The value changed to {new_value}!")

# you emit signals when appropriate (e.g. when the value changes)
my_obj.value_changed.emit('hi')

Please see the Basic Usage guide for an overview on how to use psygnal, or the API Reference for details on a specific class or method.

In addition to the Signal object, psygnal contains:

Installation#

from pip:

pip install psygnal

from conda:

conda install -c conda-forge psygnal