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 more 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.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21132b6ae5a7cfc8b2078b24cc3d7dc59fd07d867f649e10ef092976c4b8e33f |
|
MD5 | 5062ca1406046448ead91de092eee938 |
|
BLAKE2b-256 | 2a8519781faa8dbb438913ff081060f5893ec42acff3b70d6ea8248fa835518b |
Hashes for psygnal-0.9.5-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d332a874263951e0a0158e3cef82601bce8e1cfe6f4c57a8d20d02f942e8bdb4 |
|
MD5 | aefd855d2c028e0150ca7b0ccf1e0206 |
|
BLAKE2b-256 | 106ee121cada88922d9beb3a236fed566e9546605069d1d17309e3ed3ac55612 |
Hashes for psygnal-0.9.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05cc3b4b253ea6d8efda736de89a6174c1b958a359f78a7842b8049fdfe4ef74 |
|
MD5 | f256da38dd3a24790cd1ea5cba2ae77f |
|
BLAKE2b-256 | 7d9f242a8f074fdb6c756466a04b99f5cce40bdf604216e0573222955b98937e |
Hashes for psygnal-0.9.5-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d41e16a19e98b79431c33183611e961ecc74610987249e52bae097774f3aa71 |
|
MD5 | 0337b1db5b074c89cb0c25a605cdf21a |
|
BLAKE2b-256 | be764d76a73187c349c0c094d3b6e8fe4a3d3779027672007b5a4704c7a2448e |
Hashes for psygnal-0.9.5-cp311-cp311-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5412575ea2db2b0aa783463185cb10d1ccd227fbc29fd971aabacca1fa97113e |
|
MD5 | 7341af937e178cc8eca9b73b9fae21de |
|
BLAKE2b-256 | 627726e416a8f98b471e829a478eb5da138689cf4b39a418b5387ec543691ced |
Hashes for psygnal-0.9.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43160c91eef076d83f25fdf38460ad23c6f78a2740988eee335b50aeea566ac2 |
|
MD5 | d00b13b06f40b057375771e4c04febf0 |
|
BLAKE2b-256 | 287812894d26a1cd1fe500877a4f1fe36ebf9e2d228bb637284254388df31c4a |
Hashes for psygnal-0.9.5-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39890829750905553776160746a9433ed6c7b9cdf4064b7d5e1d958b808b37d7 |
|
MD5 | 356e0a7768b57d143b2a64d6aafc2f7c |
|
BLAKE2b-256 | 6f34719f769526358f38f2068126f89ade61234a1126af40daf2fba3a955e2ce |
Hashes for psygnal-0.9.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a3ff86f5c20469419e67a00ad913d619afe10a488e2abbb9fff8683f11bbaef |
|
MD5 | 852f518284bef24384e0cece6423e1f6 |
|
BLAKE2b-256 | 93120fa5d7c556f0bf7403d84db6ef71a70054d423180757f9ee34c11700e612 |
Hashes for psygnal-0.9.5-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9f6b5cea9b11fd14ed1ac78eef33c4332aebc4862736883960e7e513404b7ba |
|
MD5 | 807623874ccb2548ab8a2f934b08030d |
|
BLAKE2b-256 | 63000a145b16e1d386250ee6334bbe41807bf0544d513346799571624eaa5cc9 |
Hashes for psygnal-0.9.5-cp310-cp310-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a55f5193c070f683542c373028084c0a1f8fa247f4500c66a01b17f96f4314 |
|
MD5 | 240de8e5684901e9dabdc6bf16a1e059 |
|
BLAKE2b-256 | cfd9259bf079699a088d2e6b8970991335ce9c7f402fcec3228042c4eabb3d06 |
Hashes for psygnal-0.9.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f511de71282598c30f4a0ce268300d384dc8d4dd536ceb0e4b47759558931282 |
|
MD5 | d0c83ed09f692e0233cd0b279636cab9 |
|
BLAKE2b-256 | ad5dde82e5c9d6da9186ba4788418b4ff6ac142d6fa8fa6d020ee859f6bfa994 |
Hashes for psygnal-0.9.5-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb85ed3e8d22d97d98f86af714eec0a3458a659bf72296423036acc7acaa29ec |
|
MD5 | 912875e7149039ee4fbca876e343ac75 |
|
BLAKE2b-256 | aaa96ff7aaab9f6222bf16f9d95dce17056fa2997ab9b5a0e1f4f1487ebad809 |
Hashes for psygnal-0.9.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42d6168e891050005c7b7474897c35188b7be7f62bb88efe93985d6c6a50a9c3 |
|
MD5 | 3d654b5a04d1aad13a6b8cc92eaf777e |
|
BLAKE2b-256 | 75cb42205fe2e22f92dd9a047182292c97a4a55988761f1203e185e4783c47f9 |
Hashes for psygnal-0.9.5-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 407ee58cac4b683f58cf0ccae21ad8c0371aff4cb6b55f531ff61aca73fdcf0e |
|
MD5 | 50aa5735b202e3d15d7535efa6a36e68 |
|
BLAKE2b-256 | d4e197ebd38430a4ca3ef5eb42c0e773e9ec7bbf4b823b937c739dbccd4344ea |
Hashes for psygnal-0.9.5-cp39-cp39-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef576ba8dde2b2b5f786a37bdfce3b4608047c69c55653be071855c32f012f99 |
|
MD5 | 73b11e752d480c613b1eab66df17f5c0 |
|
BLAKE2b-256 | 88904ccf13f7bf0a2aefab483b791665f02eb67c1b4569caa9286e3940742092 |
Hashes for psygnal-0.9.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2f0623a1cbb40791e6e6787f6859fad52e65241d34f516caaf9968663d5405b |
|
MD5 | 1b5706fdbebbe6df544f44d5f5bdd059 |
|
BLAKE2b-256 | 469ab46befcc5706b2469a15edbd2e644895959d131f7fb7b45314df9bfe98ed |
Hashes for psygnal-0.9.5-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b6e1249240177ff1bfc7dd19df983bdaba0a59361613ff9138b8f0349787d9c |
|
MD5 | 299f16e04cfc820d183bc62f0b334c98 |
|
BLAKE2b-256 | 7ecd27650856292becca671f95d314e35da426e8d0287ace9b2792a06f2fe242 |
Hashes for psygnal-0.9.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8fa4929a66ba776d98f119db8d87f144d102c86c4ee9893a427507bde46d704 |
|
MD5 | 29ff297ea84186fbae14aec8ae264fa2 |
|
BLAKE2b-256 | c7f50984954ea5d508386bbd5eb113b59a8338ef510a24830fa790edcf409e6a |
Hashes for psygnal-0.9.5-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf0d0c9bea1f8c3d379ae6ac52d87c52b4fe62a651db2f06e92b964fb7bc2539 |
|
MD5 | 2075d1fb2891b6cf3884881d572524ed |
|
BLAKE2b-256 | 2056461e405d1f41a0a73cf0c3082194b37a9e2e9177e370ef169b0b8c3573a9 |
Hashes for psygnal-0.9.5-cp38-cp38-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06b79289705888199d63bfa0579be85b15df7df578c27d2bb54f0f51e7faec44 |
|
MD5 | 5606c955a34f6adee523af607ed933f6 |
|
BLAKE2b-256 | 83544542b98c8bcc5e569c7de1388cc20e998b0fe4770d9a3ecdcffca30f8afb |
Hashes for psygnal-0.9.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b575dd9b8a8b221104ca51ebc44bc7b06f2425991401690c46633befec2721 |
|
MD5 | c951d54c292e8a5e80478fa2d4d83fde |
|
BLAKE2b-256 | 2c2db606471961a652c213295b27e31815ee32d129e33af0f27a9f515df43f95 |
Hashes for psygnal-0.9.5-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db88899c1da064e54fbac9fdb49fa34e73d762918fdb6c541c9f90fb6c232161 |
|
MD5 | 22edb1699be1a34798e667ad6c8bfd50 |
|
BLAKE2b-256 | 422f93013543138f85cbe7f8cb119f95bdc24d4715a72fd4bee7901945a7b976 |
Hashes for psygnal-0.9.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2338ea6e3a952a93a1b524e674ae1176666c0cd887311d8e93716e19f05a9da7 |
|
MD5 | e01c3875aacde8cece33a061ffabc73e |
|
BLAKE2b-256 | 9535b17dbbafa69eb161d6e07c84bc0c2139c7ec9a3f09e7ceb1446b06949904 |
Hashes for psygnal-0.9.5-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a379aaf7b6e4caf107851c5d948694ddf3e1ce4ca83a16ccd0dceee870e2d5f0 |
|
MD5 | 38385d67a38a423e4efa60bd725634b4 |
|
BLAKE2b-256 | 64de923c29ba4601afacc8186612deb32d2027e6c172b29d476c0c10cf612565 |