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.8.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 815124ba4a2192d2d72705dd5ba0de7d0461c923e1cb150e32ee7a096a4faf38 |
|
MD5 | 8f699e81b448ea0a5f629a2de40f67ce |
|
BLAKE2b-256 | ac57926d9912a57371233b48a6bf2705e65001576b0f7d73b73e6468b4624985 |
Hashes for psygnal-0.8.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7b1891e2f4426414b8ab4b313a01d5a0b5e4afde0dcda24433d57bdcb505877 |
|
MD5 | dfdfda0a620dc029d22c39ad85cd3af9 |
|
BLAKE2b-256 | 4fe24bc0091a0aa75363968481460209cd8a6b77a4d151ee483cc2a587b2231f |
Hashes for psygnal-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9765712e80dd1e075de1d02974f0e3f98682612120d31909ab6bcdaa2734b57d |
|
MD5 | 4c42578078cb137db3d4961e266cbc12 |
|
BLAKE2b-256 | 39296ee041eefc15889da012fa01464da7f31b40dcb57fe26110f98be6d35ef6 |
Hashes for psygnal-0.8.0-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0610d092543f6bd8405c4720ae5bc1110137f9dd3ce36d19ad390b3738b78a7d |
|
MD5 | e4331eb68356406ebe045da3a84f2bb8 |
|
BLAKE2b-256 | 77e34bf4bb8f1accaa6c70497864100d00931f8234b5b72576bde16c29545cf7 |
Hashes for psygnal-0.8.0-cp311-cp311-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4f6948831783a93cc290419bd04bf252202a07003a7209c2a22d665110bbef2 |
|
MD5 | 47f6898b2e73386ab508eccc5a914916 |
|
BLAKE2b-256 | 4869ca84d8443b42ac31e21a06d2b77b92f655c89c2fa4a549e32c1c024baced |
Hashes for psygnal-0.8.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc04c8f5b8ee8e867d2ec4a5c581fea608b8c2531a829dfe2c44cc2f345b656 |
|
MD5 | 2de9f1609da234fab25fffc773656a6e |
|
BLAKE2b-256 | 3972c9c5243f0637f4398a10f329626dd3e9e635ce8671c43443e2b72722673a |
Hashes for psygnal-0.8.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4d95af8ee744a0bf8d2177c41b211198fd452b1cfc287e30fa1677b7dbd2f4c |
|
MD5 | 781b4dead583dac652599914eec56e32 |
|
BLAKE2b-256 | df765f5674273f38ed8bfbeecf731e805bcd0c6129ad83e300c39fd088cfb73d |
Hashes for psygnal-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc4d3dbca6e248118f0f828c7cf013a559fedf490d0045866299b5e8c21180d6 |
|
MD5 | e5b271314e497879ee051b4c4aab95e4 |
|
BLAKE2b-256 | 90226a54a6074547f20e964865347df75937051cb678b3a9effc48a3b1ec4bab |
Hashes for psygnal-0.8.0-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c981a1092b589238e68042f223b2b13a36c83b1de3716e029b49ad842adb1c8 |
|
MD5 | 02dfbc13a8e94d4eb0ec902b641a103c |
|
BLAKE2b-256 | 4521b8b657f66f27f46199111600d8a42763f96f1f3eccf7849c565d42d34cce |
Hashes for psygnal-0.8.0-cp310-cp310-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a86070bbc3fea19636def5a6d57dad4fa70386ffa16152b1f1eb802c99a5b416 |
|
MD5 | b7c78c27179eb8652b9e3830738a20d3 |
|
BLAKE2b-256 | ab635faeda26c2a92dc64924116d457ac5546a3ebb4e65085984985481900441 |
Hashes for psygnal-0.8.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d704e54d410f7d67e0fedf85e0721f62a29494150bf756fb474be3fc5183f9c |
|
MD5 | 4a401d4889b85164c8fe8edd6e65c8a4 |
|
BLAKE2b-256 | 680f3174a7e7baf1799da979d54fb48267bf0b864e3c44d5b03b26ec69871b62 |
Hashes for psygnal-0.8.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c666a73aed371853d6a959f83465fc9f2a1b92e37875ded8966cce81cee50e3 |
|
MD5 | b6f2f1b70a0224860831a1d836fa59ea |
|
BLAKE2b-256 | 77718a636d1514c15b1c5bcee1a4adf4e56e358185b8b2413234b5dc1655f651 |
Hashes for psygnal-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deb7a6d8482ab8a5c431b410c00d8ef664127eacbd9c99a0d3dc27acbec40c5a |
|
MD5 | a274e462799d28fbc95c9bb28555592b |
|
BLAKE2b-256 | 57cd6247dbaaaf688de5a418b5577ce5816c463d4fc31edf31d010b994c81ff4 |
Hashes for psygnal-0.8.0-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e838f2e9abd39bb18166dbf1aa844dc89e23ebcef1190cd362749384ae5a301 |
|
MD5 | 72129a7cd06cee7efefe53b66cad8432 |
|
BLAKE2b-256 | 0f9b0cff787db8d6a1a42f323c97858e4dd514c97d6fa65e51a6c5a7ac079067 |
Hashes for psygnal-0.8.0-cp39-cp39-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72029d6a023b719820287aad8e22984d8eb32a3a9089d972c2a7cc64ca36f141 |
|
MD5 | 60eef1a61bf701e45723f43ab7ea707b |
|
BLAKE2b-256 | bc86e182a267dcf4635820e2a9b08c109692e16c41f1e58f98c3a333d276ac01 |
Hashes for psygnal-0.8.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e025855dc8ad65b16a2e46392e3855d5507612345fa11ece84bdac52485b9c |
|
MD5 | d900ab784f0c10d51510c4c51f17c9c2 |
|
BLAKE2b-256 | 3c05c46594312f7df7e269c40013226f5e884edabf918d6197216dfa10fffda0 |
Hashes for psygnal-0.8.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50871580d1f074ecb069c98bd2a527d543bd6d365749f0595f816b0cbac71558 |
|
MD5 | eaab6a49f6faccdcda9fa8737bca7bd0 |
|
BLAKE2b-256 | 72b435c00caf9f7d8a8a1fef47bb8d98d5659ee627b3e5f9650b6a3dca7696d0 |
Hashes for psygnal-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fb0d84946347fd16dbe29ed5292b605a7dd9d90658ff30fb3c6630f63443f6e |
|
MD5 | 611fbbb70f1e4b1bdff7f4d0545ac396 |
|
BLAKE2b-256 | c9783b774b754761e94777336e0a3daeb5f05e7bf9de7daf5e1bc5c0c55fea30 |
Hashes for psygnal-0.8.0-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b972b1297f0162cc58eeb16cc81b60d7194fef5c160401a84db439413eaadca5 |
|
MD5 | 0e1f54e55864f60a8d5c96d8c0deb2d6 |
|
BLAKE2b-256 | b9aaa4263497d5b79de3af36fafd1cff0fa29c1c3d2b6b6f6fe7b02e091fb9a7 |
Hashes for psygnal-0.8.0-cp38-cp38-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44a957a9712fbfaae2f4cb4220f24b56aa16d885c20c34758149f93410ed7ca2 |
|
MD5 | e784a5d87f0824673dfe4d12493988ad |
|
BLAKE2b-256 | f7b6f0614463d63099db80a545b0f09d7b027eb09023054d4229c7c52e377d10 |
Hashes for psygnal-0.8.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b757073fc24bd29aeeea50967929c7e1f2c5c3d7ef92e01a9db1437c7560f91 |
|
MD5 | e9e1fa8f6ece186361172a4fa51b2cb4 |
|
BLAKE2b-256 | 359d6f72ab52a0153793aa345ba298ec941cb4dfa23d54a728dbc7da617d74b5 |
Hashes for psygnal-0.8.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d862761d6777d9719ed774b211803c16879a0d25b767f48411f460b89d1904be |
|
MD5 | e30bd553153b5a8e7182ab1b8c7ae046 |
|
BLAKE2b-256 | 7e986217e40556a823c9aef2ef1a0ded21ba06ddf2d25e8a00cba71adbb7de74 |
Hashes for psygnal-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5a1989d5a28940d0b418dcee5c640718b0cbe774c6aaca44290514b3f8e46ed |
|
MD5 | 603e3611419aa0c03c76fe0e2f9fc63f |
|
BLAKE2b-256 | 2765477d2f1fdc33270b1cfa47c0a07f95965c274680f163ac5c779599e669b4 |
Hashes for psygnal-0.8.0-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cad05113a3d475659237f5af30a72be09b1fdbadfb91c44561c8d331d94ae06a |
|
MD5 | 975287ea357c47bb7d8c8fcbc4dfb232 |
|
BLAKE2b-256 | 675fd00e5bded2bf94e1900434a65bbb0d86f880f852bed81d9cee82f022dd73 |