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

Uploaded Source

Built Distributions

psygnal-0.10.1-py3-none-any.whl (73.1 kB view details)

Uploaded Python 3

psygnal-0.10.1-cp312-cp312-musllinux_1_1_x86_64.whl (690.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

psygnal-0.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (708.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

psygnal-0.10.1-cp312-cp312-macosx_10_16_x86_64.whl (423.9 kB view details)

Uploaded CPython 3.12 macOS 10.16+ x86-64

psygnal-0.10.1-cp312-cp312-macosx_10_16_arm64.whl (404.4 kB view details)

Uploaded CPython 3.12 macOS 10.16+ ARM64

psygnal-0.10.1-cp311-cp311-musllinux_1_1_x86_64.whl (661.8 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

psygnal-0.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (684.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

psygnal-0.10.1-cp311-cp311-macosx_10_16_x86_64.whl (432.9 kB view details)

Uploaded CPython 3.11 macOS 10.16+ x86-64

psygnal-0.10.1-cp311-cp311-macosx_10_16_arm64.whl (405.9 kB view details)

Uploaded CPython 3.11 macOS 10.16+ ARM64

psygnal-0.10.1-cp310-cp310-musllinux_1_1_x86_64.whl (672.6 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

psygnal-0.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (693.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

psygnal-0.10.1-cp310-cp310-macosx_10_16_x86_64.whl (440.1 kB view details)

Uploaded CPython 3.10 macOS 10.16+ x86-64

psygnal-0.10.1-cp310-cp310-macosx_10_16_arm64.whl (412.0 kB view details)

Uploaded CPython 3.10 macOS 10.16+ ARM64

psygnal-0.10.1-cp39-cp39-musllinux_1_1_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

psygnal-0.10.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (688.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

psygnal-0.10.1-cp39-cp39-macosx_10_16_x86_64.whl (440.1 kB view details)

Uploaded CPython 3.9 macOS 10.16+ x86-64

psygnal-0.10.1-cp39-cp39-macosx_10_16_arm64.whl (411.9 kB view details)

Uploaded CPython 3.9 macOS 10.16+ ARM64

psygnal-0.10.1-cp38-cp38-musllinux_1_1_x86_64.whl (662.7 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

psygnal-0.10.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

psygnal-0.10.1-cp38-cp38-macosx_10_16_x86_64.whl (433.3 kB view details)

Uploaded CPython 3.8 macOS 10.16+ x86-64

psygnal-0.10.1-cp38-cp38-macosx_10_16_arm64.whl (406.8 kB view details)

Uploaded CPython 3.8 macOS 10.16+ ARM64

File details

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

File metadata

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

File hashes

Hashes for psygnal-0.10.1.tar.gz
Algorithm Hash digest
SHA256 7e546e14d89434fc94bc6ff6bbeaf6bb8a039e5ed85fc6c992bb427be47fcfc7
MD5 9716f751ace624ba61291cb15fc923ac
BLAKE2b-256 aeefd568098964f32a1682c5e8e4a91ce24ffc392d826f8e57438ae35b92e0ab

See more details on using hashes here.

Provenance

File details

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

File metadata

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

File hashes

Hashes for psygnal-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e0488cfdfeeaaf6c3b5b3b84e14ca89cd45b0bbaf43f83fe39a4924e2f0d358
MD5 6cf71aa025866f9b4283f674292341a1
BLAKE2b-256 4049c27b1ef569e3a72ac78e262e8f43d5ca208771623829fe7b8f355bd16cd4

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6b238824e2739512f26f121e921af211360bc6faf233bdf09d9ffc202a57b284
MD5 074819ab02275f6fd0a9a128af881fbf
BLAKE2b-256 84b81dd649dd3be40e2d3a998821eddce4a0a2c26aa21c1ec79a5b22dca38569

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 793eaf8edb01514075c422daf0ebc593235ee6b6d96a27196ba6dceb2bb05e1e
MD5 d7ca28db8fcb96bbcb457cdeb7608b4b
BLAKE2b-256 a1eb837d83aaae3a83cd78d63ee9adf9880f918ceae5f22b23b9c342a40d7390

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp312-cp312-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 3253518448fcb288399cd1ed6f7876bf110d67d6d3f427b720620ec1f6b72bba
MD5 013701167da30484ae282e972c14fa37
BLAKE2b-256 51d92722c8d634ca2e19b312239f232ebb3d4994c3d8e17276e8415a214722d5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp312-cp312-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 f10d1d2bea4bbb3639538a3f85794359728833f85ce2ad92a1e04aa8712a01c7
MD5 294cff01b2cbca719157e8aee2cb74d1
BLAKE2b-256 86e16569157aee016c8c90ee8bd50f30447b787e09fac4027bc1997e535ce9af

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b1a315e373040c3da451fd6ce32e2ae1bf72b9e83bdb2a36eaaccdd9b8a4ee17
MD5 c7e5f7f1cfa074b5ebd774813feceb23
BLAKE2b-256 e70a8f29d00d150ca4ae3470249b7cd513290c34421a6f39730e3d4218876d59

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8e07ab0295848f5669618201c6ee71b27623d96cb5a5ba4a60992edf5807834
MD5 3610d1582bd7a28212d9c03cbc59ac22
BLAKE2b-256 0908f299cef473c0011a1e51ddba159752f9d7373f15d306cc20f1a27c9bbfae

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 496e7bf61dbad3a1334191dba3e3e14612958052b1d19eaec2d79caa6729940b
MD5 f9a3e09862c7a3373913b8ddb11a32eb
BLAKE2b-256 42e9507d3589fbc0764943f7c8bbdc14a9c55145ed250cdf274237e3b997abf7

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp311-cp311-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 063460578b89807d0dfba2e9c362127590ffa34b9357a42e147abed187013e3f
MD5 52100cd48980857c0d5940d96869c9c0
BLAKE2b-256 4ba219a4951a4f925a98f1c4e2d003d11586433eba715f48af323e09afe7b796

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 4b91329eb39f4e2c0cc668bf486ef41fab4ac975b542088d365408f90af3b976
MD5 cdbc29cd3a7b16318fb5686bf686f64b
BLAKE2b-256 e4174fd806e6cd6ff7509d8d3ff48590e9b31c7626cbfd2909233051ede50b70

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 daa5950bfad9b5afe3f397930bc6969c11c6adfe57e3fc3455ef621e3de210db
MD5 0a92d5480efb868baaecdb0e5f859f46
BLAKE2b-256 c8966753e0fa5c5be09fe2d0804c62dc76278f60a57942fc2383ff8202c985b8

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 dfc0f414aa30f713aca3e55221bec8cbb9b17ae83ca1c1b4320ec43cdf1bae21
MD5 5e4b8f2d4822013c3849b3787c2b7a41
BLAKE2b-256 7d7004b72e36e1e2cd4595a708331ae124e61b27f5f5ad80e1c4a17a1a722a69

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp310-cp310-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 d2c21860a44f35f5432dfaccbde1f6df82976d8a1dfad04e4a5948e9482393af
MD5 15adaafea95bcc461ef8696bce18d843
BLAKE2b-256 772b33b6de650029be0f67b61ce656a8830f7b6c7ccf3b1630aba371d9b12497

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3b371501a00efcdb479716300ec9e71fb3e494f383e3c1309070fc2ea22e07a7
MD5 6996d6c4259d2a2cefb0172c2f6ca809
BLAKE2b-256 42f3b8cd4870575fa64ed5b5c7582453f014bf64e58cbb56c69673ae44f85a4f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc8e455c74abe5039b4522ad4c5714b96e99db73124ece1112c9ab4b10127a0c
MD5 9d023a15d0275867b5138e0d0c1267d8
BLAKE2b-256 28383a9f87468c187c6521f8cd8e554456d7349aef8c62b6b940ff0c374c7745

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 2159589b19489be97456ff88aa6e9c5aa930a57f766e9ff9674198b13d9700e2
MD5 8e7a06f6e565d00355565ed9c50977a0
BLAKE2b-256 ae64ba48fd06a1857f2972ea5ae61b61fbc8a8e91ec61c8a57630e4f3ea42657

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp39-cp39-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 a6752f9ace2f21da9da51d9c0fa84b1111ef1ee36e65349da0286cd82a726e80
MD5 44e18c3ef136c3aa4b3342ae2ef2961d
BLAKE2b-256 21e49f4c76f8806c09dcaded001a3538d48a218e269c47932ec2c368c341ed20

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 39f500cca6e323640721ef44265940cbe2037139846bf4af75633bc211918115
MD5 39d45914d59c22f1d0e74be259e557c7
BLAKE2b-256 22a1ed32bd9459eb6ba31cc68f87636e4441a0e7b3f1b3137c0620aa80391c8b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 079ba217491ca6d052a85609b376c131646f007df8b320fc1071d33c7ef19f5b
MD5 225d08cc405b2a4e6ca7eb7b6b3c1c6b
BLAKE2b-256 ac71b45a3ac7f0a24118d5fa9f375d463a7767db6e829f93dd96f91e2fcb8a7b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 ada36f3c12ce7b3c06012aa39da7a44e87cb2a31d1bad9afa7832f93324b4e6a
MD5 cd20ad4a671e529b63aa8f7dcf93545e
BLAKE2b-256 0bc82c8d19978683c96f6e00f80f0af1c39ebd05c66566131024cb6db213de65

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.1-cp38-cp38-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 b8cf76baf9a3a1c3206618dad57275cdb97c0e5236e06459802509dc699d87ac
MD5 589ac2bde6222177dbb13cd1d91cb84b
BLAKE2b-256 922495c53651a25e581fd2a75c94ca400675228410b34c20082c01690c35c48b

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