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. It has no dependencies.

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.

Evented Containers

psygnal.containers provides evented versions of mutable data structures (dict, list, set), for cases when you need to monitor mutation:

from psygnal.containers import EventedList

my_list = EventedList([1, 2, 3, 4, 5])

my_list.events.inserted.connect(lambda i, val: print(f"Inserted {val} at index {i}"))
my_list.events.removed.connect(lambda i, val: print(f"Removed {val} at index {i}"))

my_list.append(6)  # Output: Inserted 6 at index 5
my_list.pop()  # Output: Removed 6 at index 5

See the evented containers documentation for more details.

Benchmark history

https://pyapp-kit.github.io/psygnal/

and

https://codspeed.io/pyapp-kit/psygnal

Developers

Compiling

While psygnal is a pure python package, it is compiled with mypyc to increase performance. To test the compiled version locally, you can run:

make build

(which is just an alias for HATCH_BUILD_HOOKS_ENABLE=1 pip install -e .)

Debugging

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.11.1.tar.gz (102.1 kB view details)

Uploaded Source

Built Distributions

psygnal-0.11.1-py3-none-any.whl (77.0 kB view details)

Uploaded Python 3

psygnal-0.11.1-cp312-cp312-musllinux_1_1_x86_64.whl (725.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

psygnal-0.11.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (743.8 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

psygnal-0.11.1-cp312-cp312-macosx_10_16_x86_64.whl (444.7 kB view details)

Uploaded CPython 3.12 macOS 10.16+ x86-64

psygnal-0.11.1-cp312-cp312-macosx_10_16_arm64.whl (425.2 kB view details)

Uploaded CPython 3.12 macOS 10.16+ ARM64

psygnal-0.11.1-cp311-cp311-musllinux_1_1_x86_64.whl (695.3 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

psygnal-0.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (717.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

psygnal-0.11.1-cp311-cp311-macosx_10_16_x86_64.whl (453.4 kB view details)

Uploaded CPython 3.11 macOS 10.16+ x86-64

psygnal-0.11.1-cp311-cp311-macosx_10_16_arm64.whl (427.5 kB view details)

Uploaded CPython 3.11 macOS 10.16+ ARM64

psygnal-0.11.1-cp310-cp310-musllinux_1_1_x86_64.whl (706.1 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

psygnal-0.11.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (727.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

psygnal-0.11.1-cp310-cp310-macosx_10_16_x86_64.whl (462.2 kB view details)

Uploaded CPython 3.10 macOS 10.16+ x86-64

psygnal-0.11.1-cp310-cp310-macosx_10_16_arm64.whl (433.5 kB view details)

Uploaded CPython 3.10 macOS 10.16+ ARM64

psygnal-0.11.1-cp39-cp39-musllinux_1_1_x86_64.whl (700.0 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

psygnal-0.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (722.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

psygnal-0.11.1-cp39-cp39-macosx_10_16_x86_64.whl (462.2 kB view details)

Uploaded CPython 3.9 macOS 10.16+ x86-64

psygnal-0.11.1-cp39-cp39-macosx_10_16_arm64.whl (433.8 kB view details)

Uploaded CPython 3.9 macOS 10.16+ ARM64

psygnal-0.11.1-cp38-cp38-musllinux_1_1_x86_64.whl (696.5 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

psygnal-0.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (699.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

psygnal-0.11.1-cp38-cp38-macosx_10_16_x86_64.whl (453.3 kB view details)

Uploaded CPython 3.8 macOS 10.16+ x86-64

psygnal-0.11.1-cp38-cp38-macosx_10_16_arm64.whl (428.6 kB view details)

Uploaded CPython 3.8 macOS 10.16+ ARM64

File details

Details for the file psygnal-0.11.1.tar.gz.

File metadata

  • Download URL: psygnal-0.11.1.tar.gz
  • Upload date:
  • Size: 102.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for psygnal-0.11.1.tar.gz
Algorithm Hash digest
SHA256 f9b02ca246ab0adb108c4010b4a486e464f940543201074591e50370cd7b0cc0
MD5 13955249103622604d4022e7d5ef94e0
BLAKE2b-256 bcb0194cfbcb76dbf9c4a1c4271ccc825b38406d20fb7f95fd18320c28708800

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: psygnal-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 77.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for psygnal-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04255fe28828060a80320f8fda937c47bc0c21ca14f55a13eb7c494b165ea395
MD5 f7c0a9e11798196604699fa0c9e27ecf
BLAKE2b-256 6876d5c5bf5a932ec2dcdc4a23565815a1cc5fd96b03b26ff3f647cdff5ea62c

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1c2388360a9ffcd1381e9b36d0f794287a270d58e69bf17658a194bbf86685c1
MD5 18fdd3e2840f86ad36d978398e2fc3e6
BLAKE2b-256 1454b29b854dff0e27bdaf42a7c1edc65f6d3ea35866e9d9250f1dbabf6381a0

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 885922a6e65ece9ff8ccf2b6810f435ca8067f410889f7a8fffb6b0d61421a0d
MD5 0c320e34a78de522d736476e2c8713f9
BLAKE2b-256 49ad8ee3f8ac1d59cf269ae2d55f7cac7c65fe3b3f41cada5d6a17bc2f4c5d6d

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp312-cp312-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp312-cp312-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 c7dd3cf809c9c1127d90c6b11fbbd1eb2d66d512ccd4d5cab048786f13d11220
MD5 f9779ce01a14f5f9e4899a020fd28a3c
BLAKE2b-256 c466e1bd57a8efef6582141939876d014f86792adbbb8853bd475a1cbf3649ca

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp312-cp312-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp312-cp312-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 0b55cb42e468f3a7de75392520778604fef2bc518b7df36c639b35ce4ed92016
MD5 e26bfc9d64f719b40e65535e149583e0
BLAKE2b-256 335d9b2d8f91a9198dda6ad0eaa276f975207b1314ac2d22a2f905f0a6e34524

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d77f1a71fe9859c0335c87d92afe1b17c520a4137326810e94351839342d8fc7
MD5 5ac5bc5f410769ff029746167f50c6ed
BLAKE2b-256 da7d24ca61d177b26e6ab89e9c520dca9c6341083920ab0ea8ac763a31b2b029

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24e69ea57ee39e3677298f38a18828af87cdc0bf0aa64685d44259e608bae3ec
MD5 5b885a1e1b5eefb7db503479d29fe823
BLAKE2b-256 846f868f1d7d22c76b96e0c8a75f8eb196deaff83916ad2da7bd78d1d0f6a5df

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp311-cp311-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 8f77317cbd11fbed5bfdd40ea41b4e551ee0cf37881cdbc325b67322af577485
MD5 9e7ca3576ea396df53660ce7c727785c
BLAKE2b-256 25926dcab17c3bb91fa3f250ebdbb66de55332436da836c4c547c26e3942877e

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp311-cp311-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp311-cp311-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 3c04baec10f882cdf784a7312e23892416188417ad85607e6d1de2e8a9e70709
MD5 72d6c4ed40b33585324541d2af1c97c5
BLAKE2b-256 a6a8ed06fe70c8bd03f02ab0c1df020f53f079a6dbae056eba0a91823c0d1242

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c392f638aac2cdc4f13fffb904455224ae9b4dbb2f26d7f3264e4208fee5334d
MD5 c70f68f3d719056e30b6094d23ce6fd0
BLAKE2b-256 a5938d91aef01261123640406d132add52973e16d74b6c6e63b6fb54cc261f1e

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7676e89225abc2f37ca7022c300ffd26fefaf21bdc894bc7c41dffbad5e969df
MD5 61dce6938f385e9d711a63e043b7dfe7
BLAKE2b-256 c33fae610fd14cdbae8735344abfc7f67c76ff8bcf18e0e3c5f26a1ca590014e

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp310-cp310-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 cec87aee468a1fe564094a64bc3c30edc86ce34d7bb37ab69332c7825b873396
MD5 88a59d69128bc8c73a1165b4d63d898b
BLAKE2b-256 660a52b7e40f4c7ec82c9809c62e568ee9c117dd911d3f6f562ac3007a4ad969

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp310-cp310-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp310-cp310-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 8d9187700fc608abefeb287bf2e0980a26c62471921ffd1a3cd223ccc554181b
MD5 14af5938b87f1c5e3733b533ef49a241
BLAKE2b-256 92bf2dee9491518402489909c0613004d3a0f79672f27ce16aae774c5addc506

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 09c75d21eb090e2ffafb32893bc5d104b98ed237ed64bebccb45cca759c7dcf4
MD5 46b02b9bea248e9fea559eb6f53ab6ef
BLAKE2b-256 b5e3ae3b178f0c0f9528a9b957f302800d65ddc6fcd47f18724006de6414fa85

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 713dfb96a1315378ce9120376d975671ede3133de4985884a43d4b6b332faeee
MD5 948d225173a2ba90dd95f786866e5bc0
BLAKE2b-256 bc0e8bfb65ad186f36a52b2bfe6193f37f3b792f548d1ccfa302b5859bd8c648

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp39-cp39-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 c05f474b297e2577506b354132c3fed054f0444ccce6d431f299d3750c2ede4b
MD5 59d72615caad62c96e7a359691d5f2c5
BLAKE2b-256 b0f8db318ba1b1e1e31455e62b83fcf754a97d061ab59a3e1c11c612abe57e48

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp39-cp39-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp39-cp39-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 c9dde42a2cdf34f9c5fe0cd7515e2ab1524e3207afb37d096733c7a3dcdf388a
MD5 44d00201b679bd8657dd8f82e644207d
BLAKE2b-256 05bd134c50dea67e1adf510e89c055bc69ea1e6487dd68af10840c9443a0988d

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fe70023fe4cf8bb6a0f27e89fd8f1cf715893dfb004b790937a0bc59d9071aab
MD5 c283f9f7740469c3ff1e644422d0a2be
BLAKE2b-256 2276b0d4f0eaadd0414755e91d8d744f8474519ee13926543dce969b9a5bba62

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc260f19349485bd58e276e731cf8be40d8891cc6ff1c165762bd2c1b84f1ff7
MD5 be1f957bcc3db2fd7479d2fc9150b5dc
BLAKE2b-256 4fb47c94454dd1a9d9b5980d9b8053b054c1f246a3adf433fbde691974e8cf76

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp38-cp38-macosx_10_16_x86_64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 36cd667dd1d3e70e3fd970463a8571436e5ae58f02cc05a4a1669e6d8550d263
MD5 ea4e81f8018650abfcb179699f17031c
BLAKE2b-256 33a7fdfa16c98b45b5823c383bc1fe5e038af01392331aa1a4e8f3a976633cc9

See more details on using hashes here.

File details

Details for the file psygnal-0.11.1-cp38-cp38-macosx_10_16_arm64.whl.

File metadata

File hashes

Hashes for psygnal-0.11.1-cp38-cp38-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 2deec4bf7adbb9e3ef0513ae8b9e98bb815eb62b76a7bf1986f1d6ed626c8784
MD5 edb51c3cdba06cec899c4fa6b6e94da4
BLAKE2b-256 a0144c3f4b9c5e723b7afd741dc529fa350d2afb584ec0ef8eda7f70436d3831

See more details on using hashes here.

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