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.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76ded540af21f25123bf0fe561b75c31385a4136af39884613509c50bd67ef5d |
|
MD5 | 41f48f61837cb37ae13c55e980b1447d |
|
BLAKE2b-256 | 81340a5272f07efb2b91748d4bbc49f4dda7efceb08cdf08de2a79b752621984 |
Hashes for psygnal-0.8.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f015e9e1299f4083acc51b34ebca17201c2fb28fbe0473a44101038508939d1c |
|
MD5 | 6a82b6ecfa82a3606540da66bd71bc7e |
|
BLAKE2b-256 | 13ef539353a7784f9460353fd5b4c39d09c87c22ddd0a4db59428f09f78c6cb2 |
Hashes for psygnal-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7f13d9ae18b996c1e3f741f650ba369116a415fb17617144c5c5646455517af |
|
MD5 | f77ec222983668a4f373cec7b14c374e |
|
BLAKE2b-256 | 6d5c62c878e908cddffaa938c02c07183c84ddb4aa07fd4ce2477ab94cd24c49 |
Hashes for psygnal-0.8.1-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c9075946ea048b138feb6522cdb92dfdd291caaabd4b64d1044e443214b26b2 |
|
MD5 | f7929da00e07f0e1aad016c2ee9ac64e |
|
BLAKE2b-256 | 78c7601a0b660304379d4684589a36308024154ff48b3ff7894bdaa66559dd93 |
Hashes for psygnal-0.8.1-cp311-cp311-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271c492cbaa13164e48ecd592d787137781f3eb8c1ee27b6d35886ef48cb5584 |
|
MD5 | d4dc49f831ababa3403101c640ac8857 |
|
BLAKE2b-256 | 5ab96f2901fc139d60e6c7c5d919df9332b5dcc2a5bff196a9e38e0197396458 |
Hashes for psygnal-0.8.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b47ace9c41acf88d3156ec60bb316d88bc6ae5ddc8a44b8acb51b3d1831d84b4 |
|
MD5 | 5a65cb99d357745e3711e689346e91f5 |
|
BLAKE2b-256 | 5f91fe97f1335782a291de4792aa7ecc6606f12ac6029cfb3650905d35487ea4 |
Hashes for psygnal-0.8.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4f7b71234a2ec3f453a0ae5c133fabf9f2138b6395da09f60aca0e64ec71564 |
|
MD5 | e0ed0e967b04aa549cfbd50b95f2cd46 |
|
BLAKE2b-256 | 37c7c0920c41dc3f7175544370ea9bc1268328fb2fa840fc449d7428d79d432c |
Hashes for psygnal-0.8.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 575d31e87010955431eff88bca12b05fb14e58652a41d4f7864dd8da574931d8 |
|
MD5 | 508beadba3a7cf7d82a5581d535c2e04 |
|
BLAKE2b-256 | c03372a8522c5c86dbd8c36f17630f632e2fbe6a6dbf89dfae614402cb5bd22a |
Hashes for psygnal-0.8.1-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aa3856ca3f40ffc94f0bf114fc389d47ea3a40cd4fe788181c5a7a9262bf245 |
|
MD5 | a68a18533f8335587a750c6b3cc5c21a |
|
BLAKE2b-256 | 357df89fae1a7e04572285d69b86d85d0599595eb98d82661b2819280e29170c |
Hashes for psygnal-0.8.1-cp310-cp310-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d61cb3bb371ce415e35bbb94b29bed399579610b081d1a123023aec12a8ffa2f |
|
MD5 | 1308dde0b26d7d8ae748cdbc0e5cb5e5 |
|
BLAKE2b-256 | 8fd89edcffe8b72e61a233e24c27775ed9d644ed48d30681727c819a208880b3 |
Hashes for psygnal-0.8.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | daacf2754572d8fd6231541ee5cd830d1a6e9cad7bb7fe9ded3e33effde64e6a |
|
MD5 | 426607a22092df9f4273db248233e10e |
|
BLAKE2b-256 | fdef6a94fffa071482868aecdfe225bbf5f9a50ff370a55c65481a3119c2d1ad |
Hashes for psygnal-0.8.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6363cec5b3359a0d9fe1da16c8e679ab80c77651041bfe9c9d768a7eb4cb66f5 |
|
MD5 | 324d0f168b08e3af18606adf66e8b481 |
|
BLAKE2b-256 | b89c4f58ca62f365101d96664d214b947a1bdaf1438fa3ca03fd8991940abc20 |
Hashes for psygnal-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80ad3436a378dd3e435a17797dd7f90233451c67e7e1a33e4f26bdd377568190 |
|
MD5 | ad1b8b7aa417c4b25d55bfa81edca668 |
|
BLAKE2b-256 | 61ba0a0cf0995cbed9427b50452506ab0b845072e3f0ea7fc931043f42ffb19c |
Hashes for psygnal-0.8.1-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfccde6e6f2a7f1accc4d0f2ca076a57927f6b0012ead1d454869a0469bdb5cc |
|
MD5 | 9bf4bee932dbdc00488cf828c2ed05be |
|
BLAKE2b-256 | fb5ba9835222e8f756a8d32c12a79d78d8529c59ada622f119f20e0c61d1fde5 |
Hashes for psygnal-0.8.1-cp39-cp39-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5391014ffa957810c246952eb0729a1030d0a039836db9726b828fbec4a4a37 |
|
MD5 | 39ce86c9552162ac7e7c523153594739 |
|
BLAKE2b-256 | 794deb9eba63e9d4f354bb896a64a89b41a19eaa45dab3b33f9a11cf3c896041 |
Hashes for psygnal-0.8.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 709999f21d65151c96010565cdefa28efa47b2123dbe065c0c7b614519b42c62 |
|
MD5 | 2e1fb675a25511a90055c728741f4bc6 |
|
BLAKE2b-256 | 54cf9093c5b0922d3364accf355cf471853ae8e463aea47cf7080597d82db384 |
Hashes for psygnal-0.8.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27e339ae3beb557c7f68fd9e9fb1644f71422d75446b58ff925bd684bdc8e209 |
|
MD5 | 83efde1cff7656c80693a4721cbdda7d |
|
BLAKE2b-256 | 864d574ef0a42b32fd39b8b7033de9a1008490bd793814c178ae53e46365392d |
Hashes for psygnal-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9505113d835573e485a67ff5ba46e47f705a9885b7eb7ca18247360c2b21bd5 |
|
MD5 | 85d2d510e7c6ad55f7969131f1c2de18 |
|
BLAKE2b-256 | 77a09258c8316b99019b5c9ee0027aa6d04709876b070ea439dfe587e957bc9b |
Hashes for psygnal-0.8.1-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bba7a35496ae88b3164a47857468a4cfcb171f1cb8b093a7314017eb9058e06 |
|
MD5 | b7e728a1624f623b96ae68b21bae70b8 |
|
BLAKE2b-256 | a13d0adb16ec61dff385b574ecfa3c61eb2dfb2ea25eab0641ebf3d053a81bce |
Hashes for psygnal-0.8.1-cp38-cp38-macosx_10_16_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52fe046345d1a2dc17b9d096eb6de818a7a350ec228974db1508a431ae5ebc40 |
|
MD5 | 5f0e67a12c640b77a610340184edc1ee |
|
BLAKE2b-256 | a4352333a9db24bc88b194989d78bb334c21b04d94523fbfceb23232ac81db0a |
Hashes for psygnal-0.8.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe8e876b7d1b7df5b2d4fc44449caecfe13c10062b6937d79da437cc679801d3 |
|
MD5 | bddfa2764616e1536aae5eacb41c680f |
|
BLAKE2b-256 | cdf882ff3e1c7b1b56ca2388cab0d062b5804d312cd0710f38f83356e7bbc7c9 |
Hashes for psygnal-0.8.1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47d749d87219bd6029870498465fc3bdb0711ad991de175a0fb3d4dac0917082 |
|
MD5 | d81f62edec4885730840869d27464f41 |
|
BLAKE2b-256 | 7a4a0b4607467d62a872dc01f07d99d0d404ff43d0f9c84c59b12cd5e5310891 |
Hashes for psygnal-0.8.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d8725f09ec8b21f8e433352f45ee8d9b5653df428812689eff9d21a70324062 |
|
MD5 | 828182375f96e5bd2a579d18c3421dfd |
|
BLAKE2b-256 | 0c9555c8e04b9e36c1d073428c9e1b8a877b18f4141037e64634539147b8db84 |
Hashes for psygnal-0.8.1-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | debbd4187838c4cfd843cea9df40c9ea1f320a16fb15ef61982becc6a0de9d4b |
|
MD5 | 5f60072f484f0dd5883967836da29782 |
|
BLAKE2b-256 | 3b7124ef3e733a83154b46cb54d3360e4980c2592456260031a69c6de5607380 |