Fast python callback/event system modeled after Qt Signals
Project description
psygnal
Psygnal (pronounced "signal") is a pure python implementation of the observer pattern, with the API of Qt-style Signals with (optional) signature and type checking, and support for threading.
This library does not require or use Qt in any way, It simply implements a similar observer pattern API.
Documentation
https://psygnal.readthedocs.io/
Install
pip install psygnal
conda install -c conda-forge psygnal
Usage
The observer pattern is a software design pattern in which an object maintains a list of its dependents ("observers"), and notifies them of any state changes – usually by calling a callback function provided by the observer.
Here is a simple example of using psygnal:
from psygnal import Signal
class MyObject:
# define one or signals as class attributes
value_changed = Signal(str)
# 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}!")
# The object may now emit signals when appropriate,
# (for example in a setter method)
my_obj.value_changed.emit('hi') # prints "The value changed to 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://pyapp-kit.github.io/psygnal/
and
https://codspeed.io/pyapp-kit/psygnal
Developers
Debugging
While psygnal
is a pure python module, it is compiled with mypyc to increase
performance. To disable all compiled files and run the pure python version,
you may run:
python -c "import psygnal.utils; psygnal.utils.decompile()"
To return the compiled version, run:
python -c "import psygnal.utils; psygnal.utils.recompile()"
The psygnal._compiled
variable will tell you if you're using the compiled
version or not.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for psygnal-0.9.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae5821b2c7a196f8346f35cbe7a12dba31750eb40ae7d26967fc05284be3d9a3 |
|
MD5 | b35e36d2f808fbcbef7f74353d8db070 |
|
BLAKE2b-256 | e4fbec72ec77467ae06b5c461e091bd5963324c7647e64036b2d0b3240611400 |
Hashes for psygnal-0.9.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 098d64fab9a455736cb90c2a9226a4dd49837595bd7971155c33253ef7bfec56 |
|
MD5 | 57a6a37a2de10be42a35cff25698f107 |
|
BLAKE2b-256 | f74e1c5182d4694550a5feaa8e8ab44e6a69ba64bd8551888e3f547768adc7ae |
Hashes for psygnal-0.9.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c4b1cc97417838524c039e43c38445d848bca443bc083d9f235c770cbad6eed |
|
MD5 | b30921a7e3b8037eb222a16a62c9a86b |
|
BLAKE2b-256 | ff11655919658bc0c16cc46ea8d4b6a839c362cc427ef85e9b129f7bdf37b390 |
Hashes for psygnal-0.9.2-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 389ae777ec322670197f78f332064b08c2e78001fb2063a42f77e4ce53d482bc |
|
MD5 | 1e5ff63853625f5788c6542f956744a6 |
|
BLAKE2b-256 | a292c342630285754b3ea6eb4a249620f9be4f5227fbf29b2554f726f842cea4 |
Hashes for psygnal-0.9.2-cp311-cp311-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1c52b23cfedd38f51bab767d03b0ea9087699b541d2211b7378744768e1f3de |
|
MD5 | d0695eb6858293259d396028d7c3ea9d |
|
BLAKE2b-256 | adb23656ebfe000f2aa1b5186ed084a202c34204d06ce0c41b4c26ba0675fc2e |
Hashes for psygnal-0.9.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bf571a65fbfc342e6a62789d70926a5f0857ec1133e9801e637c5e06c625f4b |
|
MD5 | 25a7a0e213d2625ba5134dd025c44adc |
|
BLAKE2b-256 | 7d8e4b2ed3f4df5fb6927e095edd49d8a170abb66329800214c460c496e91b9a |
Hashes for psygnal-0.9.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 691dd5070d35e3185d83c961ec82f277facff0c993558e6cf55be08f441bbb08 |
|
MD5 | 5d8378110605dd3926b956cebda94f12 |
|
BLAKE2b-256 | 78c2cf1c3b8abcfc9e1616f59910f1cd7741887959c4a00cfae060c873c24a01 |
Hashes for psygnal-0.9.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a54521443f89fbaf61f78e157b8fbccbb22828ba8f7e554dfc090214ffec544e |
|
MD5 | 6dc07303649ec009ed0b973d954b3df9 |
|
BLAKE2b-256 | 9fd24dfcbce10100bdcc79ce7157a17d4828e8a88d49461b9fec507499471b32 |
Hashes for psygnal-0.9.2-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02c9c6a17aa8f7a5d61e8ac909503ec15f02b2aad84f23454f421490a59a44d5 |
|
MD5 | 140f8bdab7fbaaface07972cb7201699 |
|
BLAKE2b-256 | 7b878e45091a99c6c6549ef3753fad8e0a715518020bf38e9dd2948b4abd1f11 |
Hashes for psygnal-0.9.2-cp310-cp310-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 431865787b55f85d82b43bd7607e34ef97aa7545811625c53fccc0bdf818be30 |
|
MD5 | 351947cb446ff60f8cfdf3f1af84033a |
|
BLAKE2b-256 | 7c2e7ca68e7d4ed837b6f5c70205cb836c4e65a35d4b838aee7f096f24d9654c |
Hashes for psygnal-0.9.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6997b01aef3c748c394425465c8a98b5c0b0942a79962b2fa7efdc6931272e |
|
MD5 | c7e5c116ca599cb3fce418561a7ff2de |
|
BLAKE2b-256 | c96af4f963c87fe5866125704c7157707ea12c6a87914270e388f35614a29330 |
Hashes for psygnal-0.9.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6794c3bba194845c299fc75ac162b5a7ce39e9a55d4cb3ec4763474f1e1de9e |
|
MD5 | 9d204146ba3ae990885b0767ced48c5f |
|
BLAKE2b-256 | e7b23aa611248fca15336295f3fdb68959919c18780ad540693bf0e8b445a9af |
Hashes for psygnal-0.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db634af005bb43527841802cac1a3683fca8619d3306b56e4597906ef30b0e88 |
|
MD5 | e4dcd2653c5d2dab65303c7c08240c48 |
|
BLAKE2b-256 | 669f66d9d5225f6dccac75f6c1f30d4aeb9987f884e50c9afbdf4abf4e6d34cd |
Hashes for psygnal-0.9.2-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d322f3a22fdf5ea6d0b3732814ee4c2fa8084e3b2cccaac7cc65892b62e1926 |
|
MD5 | 28dcf07e6aad1a74d145745ebf8598f0 |
|
BLAKE2b-256 | 9cc926b935f86dfa14f90fab502f2d61017c7ca1166dc98c5eee9bf493a0b659 |
Hashes for psygnal-0.9.2-cp39-cp39-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a96278c7c9e0762f3b9765a4b95676825ccba99c7d3f7aca017ce5374d41f7 |
|
MD5 | 737df0a26f2a2c2b51a4333aed7c3cff |
|
BLAKE2b-256 | 37e2008fe640f5382337b0b9061c0dc1cd1ce01e55dcf283705b31a5f9952ba2 |
Hashes for psygnal-0.9.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4a94870385335d883a3a24f1642f650f50e020c8a91d910f4920d0dd63fafb3 |
|
MD5 | 448dd8bdb647f0c8506e95bdeff09f21 |
|
BLAKE2b-256 | 75a09c4e6396dfc74b18a21dd38b8bd8aaffa3cc19b8e83006aad7acd9153677 |
Hashes for psygnal-0.9.2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca4e5dc2df6af44811962db1455cd49e6e163faf7886cab0019052e41c2e125c |
|
MD5 | c5d0997cc0972c087fa608380f388f25 |
|
BLAKE2b-256 | d9cf75ac900ca493500e17626f0f795eaf0c8f5b424aaf28c04112d38f5b7fe8 |
Hashes for psygnal-0.9.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc3e12bf7c420758fa230740e9c73409fd058d9c1262fb9df7ae2e15852baccf |
|
MD5 | d476ef8be6bb449b2cec9b81764e219a |
|
BLAKE2b-256 | 4423783aee30be07a999d6279483a0b6eebc212430da44b5f31bd69e591558cf |
Hashes for psygnal-0.9.2-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b093c6398606b3f64d60a9d45ecd242b60fbbe9632f401097afb609a5537e4fe |
|
MD5 | 3aba152da0e640b13f3aec07cb4d6455 |
|
BLAKE2b-256 | 30c2b8ce92517f43d5cc66a6a7c7cf222ccbd55dcbb22b28ad1a127a33ebb82f |
Hashes for psygnal-0.9.2-cp38-cp38-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6af71c285214260bf546878c852cb89e34246b604ace0e9765fc66dad9e71be0 |
|
MD5 | f0b652f10c7703e35c87f979eec57ee0 |
|
BLAKE2b-256 | 23e41f091fb26270540cbdff344188924b72d7f20b608001fba9df4b7a5376ac |
Hashes for psygnal-0.9.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84787c9482ea31a8503effcfaa0777faa3b3e122a753fa905d7fd9a76bc1259f |
|
MD5 | c912c889680e6d59560a6efd937593b6 |
|
BLAKE2b-256 | bd89875af45f5c4ddf7f13c6684f1d69c70b8cbf8b0e1d9360dd08e9406753f2 |
Hashes for psygnal-0.9.2-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb3c867c6a7521c67665f2f102e6878ce4b7179a693ec0552e54ac31b59dcb1f |
|
MD5 | 26995ad7b6c4eccdc045166dd5f1454a |
|
BLAKE2b-256 | fbc0116e7797cd7644c19e9b8e99ba2dd1c8fedc3cb49dc4d6053c718358a90a |
Hashes for psygnal-0.9.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cd19e6bde3fdbd4d2ff3e0a3f3af46975e592755a6905b0b6343a83dbeacd14 |
|
MD5 | b70882e7d350ebca3d5fa0fe7f676679 |
|
BLAKE2b-256 | 38253e0e86d020f62293becbc5bda46914c3d81772bee285af05761030057387 |
Hashes for psygnal-0.9.2-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa64d2c01a2b48d9bb4c12914b0b4cc27f973ce2d4db61752449568f78ec0d83 |
|
MD5 | f3d3acb5bef79d593d2872d39d132a84 |
|
BLAKE2b-256 | 5ffb3bed9d2219cd937db25ce37642bf38621b8c6c692e3bb57fecbabacb82e2 |