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.3-cp312-cp312-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf97ed436a700061045731f4672cc759cdbdb0a15019d793c3933ccd68f6a6f1 |
|
MD5 | e27f023e2b7bc806f5b00249cbbba4ee |
|
BLAKE2b-256 | 377ed7e6ea021a5a37506570011f636d4ff15811de2673a5210bb324890f8bab |
Hashes for psygnal-0.9.3-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c9a3e077c07b00bf716168ecd7a7b95b3d6640005491ef243ef8ee6000e9701 |
|
MD5 | a5d25fa460420da0e353543de1d6c448 |
|
BLAKE2b-256 | 077935660c68f9f2487aa41e1f190fdfcf8f2d57900014c050ff752dc42ff742 |
Hashes for psygnal-0.9.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 483afb2e4e5b6f269452ae455684bac69e497ebe5fffafdcdabe19d5af5d410a |
|
MD5 | 7a08a4fa9b7c3b4e639333e70da98000 |
|
BLAKE2b-256 | 145f0c2377de928deb6480e739b88e95b3f048bd55b23f2caa3213394c989840 |
Hashes for psygnal-0.9.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3da541aeb88c6fe4ff68fa8c4c05f173e29d4f2b193af37d2bf935e32bea33ec |
|
MD5 | 56e90a22698afedca805d55e10b463b6 |
|
BLAKE2b-256 | 1062362ea44d99955351142f955a3ff5ca44deb602c78d200af15dca6e0c70af |
Hashes for psygnal-0.9.3-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c304a4328edaeb48c97bf70e309ad56a964c4dc8f164919cba3145c8791ef6ca |
|
MD5 | 3c0def7ac42964b53098b0b3fe9857ed |
|
BLAKE2b-256 | 15deb704f62992add91bbfeb46f4c5e7bf90b99135ed88703b75a60355f15105 |
Hashes for psygnal-0.9.3-cp311-cp311-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 795001df4bd1fc09aecbeaa354fc4ac121cd8c7d14c5f2f319240f010f8e5e08 |
|
MD5 | a281ead0c842d4cac4b725de9a125b45 |
|
BLAKE2b-256 | 16b1cc9b9feabe26105f3e32efcbcc3822760797c219e44559ac452755593d3f |
Hashes for psygnal-0.9.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffcd76e9a81d89a8edea09a55475529857973caedf16db0ccbf93c5d7647020a |
|
MD5 | 5665dfac7391a17d67516e4b5d84813e |
|
BLAKE2b-256 | aedecef17f844ade5d86b33f7fc8e25370675ed4160b64e1b3a5955ee3226e31 |
Hashes for psygnal-0.9.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38936b3f46d6be527fa44525c961447dac29fc8d9d6151aebabc576a3d4f2106 |
|
MD5 | 53e3b1bfd7efea866429b02ecf1f8829 |
|
BLAKE2b-256 | 5ce72bb1947ff52662032b14d6fbf7e5b7667fdfc6819470dc944693029aaf82 |
Hashes for psygnal-0.9.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 253d7d05642ed1c6871f09cd88d9377b9c56d4ed15e3953e8e34dd9c576d40b7 |
|
MD5 | 6dd3f7eda660cf7eda95e23ce2355599 |
|
BLAKE2b-256 | 037bf717a0c34841a70f3b9d7378de4c1c243329e1f2f43d89a192f08cdc3df9 |
Hashes for psygnal-0.9.3-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 498afff7a0144f9c599121ad92fe050f5748ded8863ec01700b1c1080c3c48a1 |
|
MD5 | 04d8a2b29c5014a5d685000b5b41c911 |
|
BLAKE2b-256 | 27eedfc6d6964de764c8df5c1f529a9fef847b79c02913490df0182877a83143 |
Hashes for psygnal-0.9.3-cp310-cp310-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aae243099589826d1436dca048fdd9abc7703c2780ecf54ac94f868cc4488a6 |
|
MD5 | 07bcb5a1bd946c0c7968cad843184525 |
|
BLAKE2b-256 | 3f4f70485e485d0a9e7ef04e3ab03dbd05a770f9a186206ab2d134b72cbccf52 |
Hashes for psygnal-0.9.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed9387d7ee6774a71491d40e024fc418fc423f64639557018938e39d512bb06 |
|
MD5 | 521d3433875fcbe2bee735d6fcd603c8 |
|
BLAKE2b-256 | dc3080c8374fecd3a25f0d677064941cc3de9d116c7d05fb35859013cbca2832 |
Hashes for psygnal-0.9.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b27c95678896248134aa6a1dcfb57b44080c8814a51d7f3321eac24a6af387f4 |
|
MD5 | 5dc7a9b0f887797031846423e2ac563c |
|
BLAKE2b-256 | 664ae5079e338052332cc6cebd47a839ef3d677cc78d239a7ddce96eb72e9c14 |
Hashes for psygnal-0.9.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe51b50dc8199fb2d341c562d1247e2000c54a73c33fc4053dfd26634e610ae |
|
MD5 | 29d5827ea4a3b4e527e566076ee6db9e |
|
BLAKE2b-256 | cfbd814b92cd92c0ae44f167c53771fdddbaf5ff2ae9bb7568aba2fd45e5e628 |
Hashes for psygnal-0.9.3-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05aba2a68764dff536c967f450e61ab4592444dff5107bc3720143a094a4e44d |
|
MD5 | 6a7c22719c57a33f5296569284261e4a |
|
BLAKE2b-256 | 1a0dfd28b5105805f54d7d67998e46682dcf1236f56eccb1af5ac8ede646d3c8 |
Hashes for psygnal-0.9.3-cp39-cp39-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77926be03a91c2a6dfa068af23c2b210384b724b434661504d4ebe171eb7d7e2 |
|
MD5 | 31dd139389f76667f0afb8a3195aed70 |
|
BLAKE2b-256 | c4422574c2fd309494f796826044d6c7ee59b4b8b4e1ce20047e5612673684dc |
Hashes for psygnal-0.9.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1866afb361ec5b605ae24d522bc9048e0c9606b08850ca97999aa9830fb9512 |
|
MD5 | 0e549a185033724f47f5499588bea485 |
|
BLAKE2b-256 | 3386fe44033e11dfa74f16037486e5ae64c510b4e6f1a367172f0c4816d645ba |
Hashes for psygnal-0.9.3-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d80cacaa608f1b4f0b4b8d3e01578cd761f04773040376ee21995076e07e3d3a |
|
MD5 | 24ea1f0eda91e2b2f030486ae7e09a17 |
|
BLAKE2b-256 | 9f05bd51ad4d9a0e84d8e8ff2eb4825992e963bc0e4bba3d121cad455c1670f1 |
Hashes for psygnal-0.9.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcef44d0e2e195ffb8393c540ea3bfecf6e18cf044ceb9a82604d52556f03a35 |
|
MD5 | 26da8e50f9f63855f9227ae3c83e6e7f |
|
BLAKE2b-256 | 895f5fdc4173cfb1f18a9cedf17afdd3d238f00e10a94a9ed5b04a983db6a9e4 |
Hashes for psygnal-0.9.3-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35012efb23022edcc875e2e69989a659c612eefba0356d8e947d9464be2800a7 |
|
MD5 | 2c72a741c1219a1341ec8243a9a92f1a |
|
BLAKE2b-256 | 5f8bcb24c7134eb31c840aa244025386d938b2b463e44074f41c595852ead6d6 |
Hashes for psygnal-0.9.3-cp38-cp38-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41b2334e7254368da87f18c4ad3be7fe5f2cd5e662255a4440f27a5d862f951f |
|
MD5 | 907ff39ddce276757ed22356f9c072ad |
|
BLAKE2b-256 | c5056e31e7717ba7363b17e2218218a736ae99b6bcb1ac0ccb65f4e9e7dd8624 |
Hashes for psygnal-0.9.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0845f70cd36d0a295b30b04a90d855e004276262d04e590ea781695201f718 |
|
MD5 | 3d9c02e8fade76af2cdaccb914e10c40 |
|
BLAKE2b-256 | b9ce03ae0ac18cec0f504d2e339f377396939e01e67e759c34bebe6decc6eb59 |
Hashes for psygnal-0.9.3-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a7d16f96267f6b2588bdc7f51de96fcf4bf874fd2b5e005c5c3b4332c4622d3 |
|
MD5 | 8e6564e5f2cb698d7ee4f98c0ef7e64d |
|
BLAKE2b-256 | 43e5c0a06d140534c8500ec85fdb47caf76db78c7034172068f56a361f7e0880 |
Hashes for psygnal-0.9.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10dffc814ddfd8c3b1acec320a082772f91431289373f3bd0774ebda6595a1f5 |
|
MD5 | 506a128549418ee5e37082db8c0e6b6d |
|
BLAKE2b-256 | 290454cffff11ebabf75e64bf0f3d4d60c1207d69a7caf883df4dbef5078385f |
Hashes for psygnal-0.9.3-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9991dd2dfe40726ce6718b43b8cf46083b7c66174ee795df4d8f430da05a811 |
|
MD5 | 330499ed13d76c37863add82b09d090e |
|
BLAKE2b-256 | ba15f0c408a5c885816def4ac7a800b165fd21ac602d8510ca1f1dc689e1dac3 |