Skip to main content

Fast python callback/event system modeled after Qt Signals

Project description

psygnal

License PyPI Conda Python Version CI codecov Documentation Status Benchmarks

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psygnal-0.8.0rc0.tar.gz (71.9 kB view details)

Uploaded Source

Built Distributions

psygnal-0.8.0rc0-py3-none-any.whl (57.3 kB view details)

Uploaded Python 3

psygnal-0.8.0rc0-cp311-cp311-win_amd64.whl (291.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

psygnal-0.8.0rc0-cp311-cp311-musllinux_1_1_x86_64.whl (560.8 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

psygnal-0.8.0rc0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (581.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

psygnal-0.8.0rc0-cp311-cp311-macosx_10_16_x86_64.whl (364.5 kB view details)

Uploaded CPython 3.11 macOS 10.16+ x86-64

psygnal-0.8.0rc0-cp311-cp311-macosx_10_16_arm64.whl (337.4 kB view details)

Uploaded CPython 3.11 macOS 10.16+ ARM64

psygnal-0.8.0rc0-cp310-cp310-win_amd64.whl (286.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

psygnal-0.8.0rc0-cp310-cp310-musllinux_1_1_x86_64.whl (567.9 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

psygnal-0.8.0rc0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (587.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

psygnal-0.8.0rc0-cp310-cp310-macosx_10_16_x86_64.whl (369.1 kB view details)

Uploaded CPython 3.10 macOS 10.16+ x86-64

psygnal-0.8.0rc0-cp310-cp310-macosx_10_16_arm64.whl (342.8 kB view details)

Uploaded CPython 3.10 macOS 10.16+ ARM64

psygnal-0.8.0rc0-cp39-cp39-win_amd64.whl (286.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

psygnal-0.8.0rc0-cp39-cp39-musllinux_1_1_x86_64.whl (564.0 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

psygnal-0.8.0rc0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (584.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

psygnal-0.8.0rc0-cp39-cp39-macosx_10_16_x86_64.whl (368.9 kB view details)

Uploaded CPython 3.9 macOS 10.16+ x86-64

psygnal-0.8.0rc0-cp39-cp39-macosx_10_16_arm64.whl (342.7 kB view details)

Uploaded CPython 3.9 macOS 10.16+ ARM64

psygnal-0.8.0rc0-cp38-cp38-win_amd64.whl (283.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

psygnal-0.8.0rc0-cp38-cp38-musllinux_1_1_x86_64.whl (562.1 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

psygnal-0.8.0rc0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (566.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

psygnal-0.8.0rc0-cp38-cp38-macosx_10_16_x86_64.whl (365.1 kB view details)

Uploaded CPython 3.8 macOS 10.16+ x86-64

psygnal-0.8.0rc0-cp38-cp38-macosx_10_16_arm64.whl (338.6 kB view details)

Uploaded CPython 3.8 macOS 10.16+ ARM64

psygnal-0.8.0rc0-cp37-cp37m-win_amd64.whl (273.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

psygnal-0.8.0rc0-cp37-cp37m-musllinux_1_1_x86_64.whl (440.3 kB view details)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

psygnal-0.8.0rc0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (445.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

psygnal-0.8.0rc0-cp37-cp37m-macosx_10_16_x86_64.whl (348.1 kB view details)

Uploaded CPython 3.7m macOS 10.16+ x86-64

File details

Details for the file psygnal-0.8.0rc0.tar.gz.

File metadata

  • Download URL: psygnal-0.8.0rc0.tar.gz
  • Upload date:
  • Size: 71.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for psygnal-0.8.0rc0.tar.gz
Algorithm Hash digest
SHA256 b17f78af0fac7945df3ee242c9676a230c9cff1199d7d8aca2e6d6c5a42f3352
MD5 1ebc909b604728b5498321e1d3e6dd95
BLAKE2b-256 991ab99aaf694a5dd39115c4beae123c7f7e0cf945fbb445a22678aa19204216

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-py3-none-any.whl.

File metadata

  • Download URL: psygnal-0.8.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 57.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for psygnal-0.8.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c41bd1d96ecf1fc7fbd21ff6c9d73253fca09f9c1ac0112506d7ee0c9953511
MD5 94a2e408f228dbe17daf7f4df5b1d0d3
BLAKE2b-256 5f1e93154a2d8f29f33dc504aadbfac35239bee24b81d2f69e925939d202e065

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5406b30ab0b1be3af9c21352d297d445ad1c6b1a749bf38692cac529d761ab32
MD5 fae94ab6097125f9868fa301594b5097
BLAKE2b-256 9cf2566cbb1a0afb5ae8e9899c8722b8657a3c68644a390215087fd5e579d52e

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 63ae33e388e1d787aa683f88b2bc8bafa0a6df2a883cfae69d05458842bef320
MD5 3c20afb6805f4de2403c470db04672cf
BLAKE2b-256 b207981fae177520794ee6f25cbb0b8f090d670ff8851005e72a4a5dd62c5554

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 314e7be7e4f5f88e9e141ff81a659694dfcb3761037db523e7d9846e517fba77
MD5 48add3cea00403f5ed9389b24a5b2a73
BLAKE2b-256 9d7b99db00ab908d9e1413b8cd19bcdc38e89f86dd1a9bcc91c1d1e9a4e27a62

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp311-cp311-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 60b1d2efbd0b2e6c73affe9b5b863d66a7e32bcbe8aa37f457f36fb3203b0fd0
MD5 4475523234c43148569575a09dd10096
BLAKE2b-256 b10e0022b0307f12b175888adc89454f38e82fe0ddd586837644c5d5a69a512e

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp311-cp311-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp311-cp311-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 e87ba025349539aaeed2f49433bb312b5742111d0173ff473986b3df9c260782
MD5 e5ebec813f59a7034a24df5eda55b744
BLAKE2b-256 c4444350184d461e8f97da3c4550e32166c95a77ece7d56c15375faf829b8c6e

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ab06c966ebeb14dfbd61565aa5ad7d8729befeb2c5746a4fe106734f84f2fef0
MD5 f78f1f3e3c3f88794dffa9e1c96f88ca
BLAKE2b-256 499e22f0293df9a8b64eadeb3805d258271ddf1d17b6a592cf7adfff2b830030

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8192289b56018491a6eea16a3de26cbb5c6cded1ed0170861b68de0b4cf2c3bf
MD5 d2c8c72a12276f3e26dabf743c3d8782
BLAKE2b-256 7de1269de748e50a79d2f914b5d613dc76e244028d5954111ed37dc0e1033a25

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d390fcfcb092427ed83b5fea0ff379570538a3eb5deee5053e229bdfec54084
MD5 9cfdc65e9716d01b7b9f633f37519f90
BLAKE2b-256 13595c27d59483e79db622c33f21ff9ec29b40b473d890a52c6000dce0abd999

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp310-cp310-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 b0a648912dcfe824f512c5f82054290a5220833be8e8da2d8a354c66144a7988
MD5 07d5eeff2e5411b53a055783f76c237d
BLAKE2b-256 ab9f03721022f0daf7939833fd1b6accb531dbddbc3f8766a47a03507ab46067

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp310-cp310-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp310-cp310-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 cf44a9b4c457b32195814c9a5e03074ee185a60e63156dbdc5082f5b5e27522d
MD5 9e4ff20c2f916f479ba6ba9ecd5b585f
BLAKE2b-256 140adf5fb235680045b8ef904ddb17a7f2f5aad2232b1e4337fae575f0631382

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9b4813db89a48337893d7f980189eba527e35db8abf6c5d3f8254b3513d0b099
MD5 54d02ec7bdbe350e9560cd8878ff5847
BLAKE2b-256 c17cff4d57e08b2c7009d1430a7a4be3dadab00cf54d6e79746cef79b4c30979

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b4d27fcd7c1db72c579ec5c044aaa798fea97f261d4a8bd04ea92537fae71dc9
MD5 ad991878e9d39b860fe9b73469e63f84
BLAKE2b-256 9ff3e61b39e232dc08f9b43109f48f7f2784217ffbfcbbcc583dc24831adcaf3

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4965eda1e8dfc34ae0cf4adda46439fb1830305bced4d064a68e3245481a389
MD5 0b46cb5fdb6f6446109426b1c7146a0f
BLAKE2b-256 99c786f79c8fca6db39321ee480c237b9c4d058b2b5d615263a998f6a43ab704

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp39-cp39-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 598a2a0630b179b013c53ae1d687e8910d304dc01bd41b27630c6efc0d99b5ae
MD5 79671b418ebcec53a17275b11fc654e6
BLAKE2b-256 8e03ae5df5b0bffc751f08a56130e3eee8ca447f6dc75cadbd46dba215ca2582

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp39-cp39-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp39-cp39-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 57c7f45102a43eaa8deb3beea7d69d6f30b160d161ed3b0999b2c69cef276c59
MD5 3b6cd54b61f4e57f6958683aa05a71b7
BLAKE2b-256 13aaf5eef2200eead83d243db1b19c291472ddebd28e19eddea4b1118874abdb

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f82a1d8362dbcf04145a89aaefc7010a69501f425989b4df3379bafcbe1e9e21
MD5 4ccbf4af81c0868114422e538c523687
BLAKE2b-256 ca0325d18199b0dfd2a010889a7e94d12c391d6a67424244044f127e771d852f

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4a460230a8ea66bed71b7bda4b7fd9d663fe9bf87c665bc4169a1ef5ea1ec94b
MD5 bab7bf195f31cb2a0c1e952bbcfeef36
BLAKE2b-256 1c9515e1dcc9866c48176c1fcb115f54c8daee29ffcd86bc6d7dd120f5733979

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 920ed305e0f344008a2ffe8666f2943fa9302621089d9589126d6af6acb5619c
MD5 2879759fa882697086819b0f56b3fcd1
BLAKE2b-256 5386eb82ee89f9d7b02fc12daff8a26d0031c53426f457637e2d5ea1dbea8428

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp38-cp38-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 40f074b33d934b2451a273cd2673b5060071c149627a5888dd33000f3c02eeea
MD5 ef6e51b88b483581cfe0c811810de480
BLAKE2b-256 02109f92a28b793194902312a0462a50e342bba2729a39541a3911cdd117e337

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp38-cp38-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp38-cp38-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 4a9275ef8b70207ae2b0c6fc147e9276389bc77d1280e4f3270a66fc58838548
MD5 904013cfdac69fe93d0a151babc9c477
BLAKE2b-256 b7ddca88b766d1f327bda3958847958ceba54a82711c8b3d6772f18942271477

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0dd7c4517a7cfaf896d29b8e9b4eaefc9dd48c5794a5308bfef5dbb41ff42f7d
MD5 baee5370e79b3b28e18698e34f97be12
BLAKE2b-256 e54dd409551d9f16d730a4dc5bdd0d0a5899e841448ce9bc65b4998be58a1b99

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4ed7ac8e827bfdf7205397b7fcd8233a326727e8cd15ec7399302fdac6959085
MD5 ff1319178ad5d5d623feab220ce26f68
BLAKE2b-256 cb88ac95b6d4d87d91040bc464aa19d5fb2decce10d888595683ff91a40322b2

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13c94ab715e724c9e3eb2543eff5c97514976e541a371dd8d427be2f880339f9
MD5 7c6b4dc70a46fcccea737ff9843ba8a1
BLAKE2b-256 88a1b03ce2f55ecda2aaca9fdb6973f520d9218bf8a83e80648e7de0fdc9cf68

See more details on using hashes here.

Provenance

File details

Details for the file psygnal-0.8.0rc0-cp37-cp37m-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.8.0rc0-cp37-cp37m-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 6d2c9ab82dddb3293dd5c1595b13bd7f3b501f1accb6450fb0751ee0a2b496df
MD5 53898fdf979e449305c71026ab29aee3
BLAKE2b-256 6ec51e349df23f8e8d7f55e00e78871fbd3e59d1d5d85a991388382d53580895

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page