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.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68419696755db57f259605ffadfc0d5377b3127e3e5ee4cb37b61b940454f787 |
|
MD5 | eeb22fb1faf1053205455a8cd9e32b35 |
|
BLAKE2b-256 | 2d961418c6a92e9b61820ac61b1fe6339be42f1a818152f7021266a7c5d77664 |
Hashes for psygnal-0.8.0rc1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88488a06f7b91286df53479c74433aa77d0b8c1febdf230024247d15c456b107 |
|
MD5 | 3888a89fbf32803de90f7cf1ef627d56 |
|
BLAKE2b-256 | 80c354ead381c2be338f3aaaae45fb61210ab46220980b750b6bf5ca966a2b5e |
Hashes for psygnal-0.8.0rc1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f572d6461e097e75022f11c5854e72c9c11d9582dec7b6c57a713b9e12feb4cb |
|
MD5 | 83d53be37addfe812dbf2213b1f03ae9 |
|
BLAKE2b-256 | d1199fa0781dcb1f1a34398100e8593df786af8ff0047bc1291b6ad34b89a650 |
Hashes for psygnal-0.8.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26ac82b8233c545017eaf1596f184452c6f533a172e89afc1d63a15dafa33722 |
|
MD5 | d0c1c881d949ac1fac6df96cbe29500b |
|
BLAKE2b-256 | 08e0c1e35a77c8d941c8118150ae55ac660f9f5455c8c8fb932f181a7fee2993 |
Hashes for psygnal-0.8.0rc1-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50972d57f64f6a4611efdde260ee28d1bca654b1847d42f801d039612ccbce50 |
|
MD5 | e96bb69e7fb33b81acc111e2ee9dab27 |
|
BLAKE2b-256 | b23f04e8d3b46cc8fdaca46470133f0f5942ff38d24a280d01b097bf96a74577 |
Hashes for psygnal-0.8.0rc1-cp311-cp311-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30dbcc7f66ce7830d6140c0768b5bb7ca6646ecae98c31a9e82f003682356ff4 |
|
MD5 | 163a63ff147cd1846f6ba88344b8c2d9 |
|
BLAKE2b-256 | 4f4b485f9fc479f0f0306e87cc4e9d47a8c311cb5afdc1d2ea5d578ca8a2fac2 |
Hashes for psygnal-0.8.0rc1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c2d5c0d46397911b88d11fbe169b8f4cf4b2982baefa98800552445e4135ec9 |
|
MD5 | 9c8d5dcc1c274172f0c3e2c318e2c31c |
|
BLAKE2b-256 | 17766e54a96cc4f96c6cccf49aaafbb0ad89931f4a414102fcb2624b303a2d0e |
Hashes for psygnal-0.8.0rc1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf9e4d83ca32571df05fa1f00fbc6df8083c2f1739e60fea65cc35ce2c2c026c |
|
MD5 | 0069b0697a49db58080e5e6c51c05668 |
|
BLAKE2b-256 | e2fdf175250ab5f05c2eb5e17d532ed5f0e162ff823d9f6a2bdb97e76009ea74 |
Hashes for psygnal-0.8.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d6f3cfe2c92bc568932e7b4f20428368314b1d8bec21151e0a960a433af6423 |
|
MD5 | ebdcc7660a139a5b85350ae5d956f788 |
|
BLAKE2b-256 | e8d8e77c43c631d634498eb9606d9d28863c7f959ce82b87faa82deba366355d |
Hashes for psygnal-0.8.0rc1-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48624682b2b8860246886ec0601c78b34c7c6d4df9d59ced2f42539d3011a02d |
|
MD5 | d626ecf4c3d5af0f816cbf6639c11cef |
|
BLAKE2b-256 | 967a6aee054e17e0c9dd0f6e3d4e3dd10e3099690c0ed8be221c83f3a4671394 |
Hashes for psygnal-0.8.0rc1-cp310-cp310-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f22cae336bb81541c13a055ccae467b12de0299e00130b09099bc8c9e8999d8 |
|
MD5 | 9e5a395eddd071f39f4413253a60104f |
|
BLAKE2b-256 | e7a9b4a879e580fb5f7c44bc0160307b5d24b6421a12101c21d8463dfe6b7696 |
Hashes for psygnal-0.8.0rc1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33988aedd71a52dd525cc3eda475f1bf6f60fa29e67a91e6bfbe9d71dc4a48fa |
|
MD5 | 087cc0b7df05e583ba77c1187f0f9fd6 |
|
BLAKE2b-256 | 1e79c3b59edc6756517b56281d73d23d2699706291bc227e5f669d90cb283ae9 |
Hashes for psygnal-0.8.0rc1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c50e80b9d8f014d55f105e145dd98c367c1b53f063f2017fe758f1c18d4a959 |
|
MD5 | b0b9400db67791fd83b0a1e3a99967b5 |
|
BLAKE2b-256 | b2ee258cf608897309fe01bd71e9b4aa34f545bb057ee81a2bf7482f5bb846c0 |
Hashes for psygnal-0.8.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e60432a5f15f8c85048ff39bfea3385b2277ac2f061e4db448a811a153b9ea15 |
|
MD5 | b9282c935a6d81298f68d159003a7704 |
|
BLAKE2b-256 | ad488cbfff635221ee5c24bb237f1a82b26d515bc76acc2422f9a686b2dd276d |
Hashes for psygnal-0.8.0rc1-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7622f56c5c42d0d3650a8cca59b5e527053f4a1f8f92a48ea8c7971f9e270057 |
|
MD5 | 07f139636e9bdf19dd095b83caadee63 |
|
BLAKE2b-256 | 4b0f38f6642a939dcd36ff892cc7a1d04e63ab545c27c4b07bcffd4e76eb38fa |
Hashes for psygnal-0.8.0rc1-cp39-cp39-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3068b942a7fa44f1c169cc4add5d5a600bd0670c9f7bb564aaa2e230877f1f92 |
|
MD5 | 8170a4f6ee3325a6365c57b83f1ea59b |
|
BLAKE2b-256 | 2935cd6a6ec4273faf1376b16124da7acba4df2e7625bc4afc99db437d403181 |
Hashes for psygnal-0.8.0rc1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 033a7fdfb5744058dc05b4a813d2e9948726ea177d1de8afe34920182d2743ea |
|
MD5 | ba7b41ccfa7d0e540e9c9f35ea5c505d |
|
BLAKE2b-256 | 9c5bf9ffb413c28d675a513c23db8ce34b5a215ddc3cfa9aac6e995fc7694b32 |
Hashes for psygnal-0.8.0rc1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05fd8cd18a56776d56967f4a550182f7af5ed419aea1a4ae5aaed150e8629aa6 |
|
MD5 | 6a44045e1de83e3bc379637dc95004dc |
|
BLAKE2b-256 | d0218ba4aa8b6e4cb2f5083d3d219b9233a2b15a982809bafd95cd67572d56d2 |
Hashes for psygnal-0.8.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b57984181a95bf69b92005a0a0ea31add79a1737baf1e6df4cbcb03f97cb56b6 |
|
MD5 | bf6a1351eabb3ce3b26d90c5ea945911 |
|
BLAKE2b-256 | 798c283a6729bec72bb22ac3b6d50ba5cf99db4cf5c1c7b2f3e65a6083fb81bf |
Hashes for psygnal-0.8.0rc1-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2c02999971da078b24d998d7c81c77ed5aad625fed8f3711b50a5d98a27d51 |
|
MD5 | cab51e75a2c2fae463e8cd94565ddd2c |
|
BLAKE2b-256 | 8bb52af76c67b4986108f0f724247fafb6543c6b500f86d2dbd331fc139b2ac9 |
Hashes for psygnal-0.8.0rc1-cp38-cp38-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 265eca8921436997477014e07164f2db869c46ef6925747ca2c9ade2cf76c28a |
|
MD5 | 722aaa058243d34f807c5e29ad91b3bc |
|
BLAKE2b-256 | 7733a233db5a6360cc358e3da949dc5492692208b96fb3d6458a996ee1c6c9ef |
Hashes for psygnal-0.8.0rc1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c2970c45607623bdd63fe389a0697db54b14fa7bfc5c2a9c976c1d13e349bb |
|
MD5 | 42ec9269b30055a7662db004c256f998 |
|
BLAKE2b-256 | c9a4d2c6227d663a6bf4db3511f5b60515d9b1c8617c58ce51584bd512b66744 |
Hashes for psygnal-0.8.0rc1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1696233c1fffb547d4cd1ccf90a36be66088f54fb8a8636a22f3fd7e9b631b7e |
|
MD5 | 4e3dbe5bf679e206bccfdf1bae12a032 |
|
BLAKE2b-256 | 66f043a213a62bcf92c0f4500eea2d91928e4df700259707cdbed6bd2e9bfd96 |
Hashes for psygnal-0.8.0rc1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee0f93de6a78a7a0fae81939c8a2a7e6202bca381edff611c96f01ae28771f3b |
|
MD5 | e6a1aa56ad24828c62893806dd6caf25 |
|
BLAKE2b-256 | 42402e6795c844ba30b8719ca5956d77688ff16a1195c6e64809399bb4dbe4fd |
Hashes for psygnal-0.8.0rc1-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f930bb46522e773a9fdbb1b6cae4c9b7f4fe18ebf4ccbc35f6f89f5f173ceab |
|
MD5 | a80c4bd0937d885396df9634b9c818a5 |
|
BLAKE2b-256 | f383ac94666b69371ea3102afc95a54d8094621fc4e9ec2892bc002ffa42a959 |