Skip to main content

Pure python callback/event system modeled after Qt Signals

Project description

psygnal

License PyPI Conda Python Version CI codecov Documentation Status

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

Note: this library does not require Qt. It just implements a similar pattern of inter-object communication with loose coupling.

Documentation

https://psygnal.readthedocs.io/

Install

pip install psygnal
conda install -c conda-forge psygnal

Usage

A very simple example:

from psygnal import Signal

class MyObject:
    value_changed = Signal(str)
    shutting_down = Signal()

my_obj = MyObject()

@my_obj.value_changed.connect
def on_change(new_value: str):
    print(f"The value changed to {new_value}!")

my_obj.value_changed.emit('hi')

Much more detail available in the documentation!

Evented Dataclasses

A particularly nice usage of the signal pattern is to emit signals whenever a field of a dataclass changes. Psygnal provides an @evented decorator that will emit a signal whenever a field changes. It is compatible with dataclasses from the standard library, as well as attrs, and pydantic:

from psygnal import evented
from dataclasses import dataclass

@evented
@dataclass
class Person:
    name: str
    age: int = 0

person = Person('John', age=30)

# connect callbacks
@person.events.age.connect
def _on_age_change(new_age: str):
    print(f"Age changed to {new_age}")

person.age = 31  # prints: Age changed to 31

See the dataclass documentation for more details.

Benchmark history

https://www.talleylambert.com/psygnal/

Developers

Debugging

While psygnal is a pure python module, it is compiled with Cython to increase performance. To import psygnal in uncompiled mode, without deleting the shared library files from the psyngal module, set the environment variable PSYGNAL_UNCOMPILED before importing psygnal. The psygnal._compiled variable will tell you if you're running the compiled library or not.

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

psygnal-0.6.1.tar.gz (1.2 MB view hashes)

Uploaded Source

Built Distributions

psygnal-0.6.1-cp311-cp311-win_amd64.whl (668.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

psygnal-0.6.1-cp311-cp311-musllinux_1_1_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

psygnal-0.6.1-cp311-cp311-musllinux_1_1_i686.whl (4.4 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

psygnal-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

psygnal-0.6.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (4.4 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

psygnal-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (740.3 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

psygnal-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl (841.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

psygnal-0.6.1-cp310-cp310-win_amd64.whl (664.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

psygnal-0.6.1-cp310-cp310-musllinux_1_1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

psygnal-0.6.1-cp310-cp310-musllinux_1_1_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

psygnal-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

psygnal-0.6.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (3.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

psygnal-0.6.1-cp310-cp310-macosx_11_0_arm64.whl (733.6 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

psygnal-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl (834.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

psygnal-0.6.1-cp39-cp39-win_amd64.whl (665.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

psygnal-0.6.1-cp39-cp39-musllinux_1_1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

psygnal-0.6.1-cp39-cp39-musllinux_1_1_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

psygnal-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

psygnal-0.6.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

psygnal-0.6.1-cp39-cp39-macosx_11_0_arm64.whl (736.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

psygnal-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl (837.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

psygnal-0.6.1-cp38-cp38-win_amd64.whl (669.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

psygnal-0.6.1-cp38-cp38-musllinux_1_1_x86_64.whl (4.5 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

psygnal-0.6.1-cp38-cp38-musllinux_1_1_i686.whl (4.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

psygnal-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

psygnal-0.6.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (4.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

psygnal-0.6.1-cp38-cp38-macosx_11_0_arm64.whl (742.9 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

psygnal-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl (839.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

psygnal-0.6.1-cp37-cp37m-win_amd64.whl (657.6 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

psygnal-0.6.1-cp37-cp37m-musllinux_1_1_x86_64.whl (3.8 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

psygnal-0.6.1-cp37-cp37m-musllinux_1_1_i686.whl (3.6 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

psygnal-0.6.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

psygnal-0.6.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (3.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

psygnal-0.6.1-cp37-cp37m-macosx_10_9_x86_64.whl (817.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

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