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

Uploaded Source

Built Distributions

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

Uploaded Python 3

psygnal-0.10.2-cp312-cp312-musllinux_1_1_x86_64.whl (691.1 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

psygnal-0.10.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (708.9 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

psygnal-0.10.2-cp312-cp312-macosx_10_16_x86_64.whl (424.2 kB view details)

Uploaded CPython 3.12 macOS 10.16+ x86-64

psygnal-0.10.2-cp312-cp312-macosx_10_16_arm64.whl (404.2 kB view details)

Uploaded CPython 3.12 macOS 10.16+ ARM64

psygnal-0.10.2-cp311-cp311-musllinux_1_1_x86_64.whl (662.5 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

psygnal-0.10.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (684.4 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

psygnal-0.10.2-cp311-cp311-macosx_10_16_x86_64.whl (433.0 kB view details)

Uploaded CPython 3.11 macOS 10.16+ x86-64

psygnal-0.10.2-cp311-cp311-macosx_10_16_arm64.whl (406.0 kB view details)

Uploaded CPython 3.11 macOS 10.16+ ARM64

psygnal-0.10.2-cp310-cp310-musllinux_1_1_x86_64.whl (672.5 kB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

psygnal-0.10.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (693.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

psygnal-0.10.2-cp310-cp310-macosx_10_16_x86_64.whl (439.8 kB view details)

Uploaded CPython 3.10 macOS 10.16+ x86-64

psygnal-0.10.2-cp310-cp310-macosx_10_16_arm64.whl (412.1 kB view details)

Uploaded CPython 3.10 macOS 10.16+ ARM64

psygnal-0.10.2-cp39-cp39-musllinux_1_1_x86_64.whl (666.1 kB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

psygnal-0.10.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (689.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

psygnal-0.10.2-cp39-cp39-macosx_10_16_x86_64.whl (440.2 kB view details)

Uploaded CPython 3.9 macOS 10.16+ x86-64

psygnal-0.10.2-cp39-cp39-macosx_10_16_arm64.whl (412.0 kB view details)

Uploaded CPython 3.9 macOS 10.16+ ARM64

psygnal-0.10.2-cp38-cp38-musllinux_1_1_x86_64.whl (663.2 kB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

psygnal-0.10.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (667.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

psygnal-0.10.2-cp38-cp38-macosx_10_16_x86_64.whl (433.4 kB view details)

Uploaded CPython 3.8 macOS 10.16+ x86-64

psygnal-0.10.2-cp38-cp38-macosx_10_16_arm64.whl (407.3 kB view details)

Uploaded CPython 3.8 macOS 10.16+ ARM64

File details

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

File metadata

  • Download URL: psygnal-0.10.2.tar.gz
  • Upload date:
  • Size: 96.1 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.2.tar.gz
Algorithm Hash digest
SHA256 adb2c38d5cecfdb1212970a3123079f6d97241ac0e772c3db79418a5cabef079
MD5 3066eb7f5b132b5c3448e3d36dbfe6d6
BLAKE2b-256 8d7fe06de677dadd73e76bcbbf672c55ae98579fb30be3c3b26e0e946b16a06f

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: psygnal-0.10.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c42f76058fa89b1cc128be55d174ff79f06cd8b6cc4e0ed3eadd5d6cf9520b7
MD5 f4fd80e1a1696845a02b64feb403a42f
BLAKE2b-256 f66b02bb70e420fd368e4b010f28ffdeeffa94ed33262791fee0d48747389fe0

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 12a73bebc739a6331a618ecaa7ad0aee410b5009ec7fa0cd5f55e521ee776132
MD5 f1578c62ae8a4ec0bb62c50b08509c07
BLAKE2b-256 51ba0a3fc341938379d1b5a6ae187992b6026f2bef748d3ef42972321c60dab1

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c56ecf7a5f4125bc0b3721c46efe80756df4ebf394aad435ae8114c95a5316c6
MD5 15ce6a243c79970abfdbea1339caf7a1
BLAKE2b-256 f6392cdd2c1904b122b227e28c574297a233e05f073cee9339719013e6c8661a

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp312-cp312-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 92e61acfd42ed89b5c6df84ce19eb4d12f9376d2ac8d47f9cd903ae95ebd0813
MD5 00e5773cc1bbacb888596c3663535735
BLAKE2b-256 65ea3d4bec9989faf1c763c7c15b1d4d180ed36978346fb595af26f85f1a5cbd

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp312-cp312-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 407729dda66b67b0f19c5a49b33c14b657e994ce4807cbdf82efc723a909b0ac
MD5 c8be8340b40e26c80fb087dca437e875
BLAKE2b-256 9649bf8ca1bb1514e90cf8a958d80269e9410433e94dcbc366b23c6ba40ca7fb

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 cd758ca3ef9a4c36589492117cf8a7dbc0f92cef8d3c179f8efb66190ce66f18
MD5 b637325e5e11380955dafb8d29cab073
BLAKE2b-256 cc1fae845d320c1f59b5f99465ac8b8ee8d3a515a4c2266819fe7b9b0ed9d120

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fffea50e36e1ff3073bc6d8d8481d4d7707e298f9f379e1824de6dee71908045
MD5 63ede3674676e1784435e355b89808d0
BLAKE2b-256 4f625ffa087855df8e41658a1cb179fb3afa71efed862e0a7dfab3e602545014

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp311-cp311-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 2a453304c48f61613d82461cc6cfa390b972cf41db8f834d3a48ee90471cd818
MD5 47ba22f203adc1f6b6e7c920390c21b4
BLAKE2b-256 c95972b8a3742186a4fce56114a0ae1df6d75046fecfa007ab17e1ff54e9b0d0

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp311-cp311-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 7bd295bcabcce237bf5d2c05e51c946f83d399bedc92bd0a1d5ab8eb82b7b69c
MD5 30d01ca74e40d54476d018f1bd7486cf
BLAKE2b-256 9f190609d607b994ee9517906199866fb4c77c3b301663e9253fdfd1af96de34

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 09bc8121adf93cca7d5110900e26252ac3b3fe0dacdb96297e1b7d93b80c4525
MD5 4a235be4c5bc9e0c5e94c2333daa9a32
BLAKE2b-256 52a049d924aba2fa0640dc1c04d381f730f32bb019456da15127c1309109df38

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55378d0eb4821875649da13d9524aad75542479e1f5817f44754622571ac4a75
MD5 f3b462d2cb8369e6bfbc3cc378a85172
BLAKE2b-256 333cb308a711202a1bc2f538a9900193863bf14eb6474b4232fa1cd35940fa4c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp310-cp310-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 a3fbbac9445871b57726d41e4d0262f738c6ecc60e3a48572f3fe5829471f1ee
MD5 735cbdea9a8365e925c7a90603474d79
BLAKE2b-256 00b501e813e8155a4d88a3330496618cfb3f4cb545d0f50941738de1705e9ff3

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp310-cp310-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 004def7d5334dfad12b3d0dcfb7e16c6e3a948c42998eda0472fcc73bb5ae85d
MD5 268cbb61614835b46d663a1bf08b14dc
BLAKE2b-256 c38c7106531209d9f93bf1189a7f08a76739e08ac7011384075ebf4c8a3b706c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a4738f8b53cd3ad268e474e4570f734ac4a23951123d14a1573e199c5294b103
MD5 171ac9699fdf80bcc18840e9448de980
BLAKE2b-256 7eeb34d066a2a1e30122dabe9364c45f20b2bb9e771117d111d91ef8b9c1232e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e56ef3992e3f09e76cacec79563ec4a65c584f86742fc099adbf7d2f61e94ef
MD5 3622e2e7ce56270baef73982a3fc1534
BLAKE2b-256 1873c04e99517965640992a2e4180fc949de9555a0d68c12254276ddb4879c40

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp39-cp39-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 e9a5ed1a1843e81928490919a09af33301fb9d7920195bbae13f050e4664e4ae
MD5 b8ff8ef296337a8be5992eca161c4743
BLAKE2b-256 350b66ac68145164b509191bdd00fdb79fcba405e5eca5c7affd99174a9a7d06

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp39-cp39-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 9b904424fb994e6c0088b3aab1d15305d8f27fa716c435dd5ebd5d58f1d6087b
MD5 fd3981f67a3831b084812632d3423a27
BLAKE2b-256 5f32373cd282a6a0cc23da2dea815c4e86403963ace9e70ff2afa40ab6d66dd3

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 b9cf48ef4be9ef473edb68fb89241a0d6ee787e1c4c8c81a19a41b16db90bcb3
MD5 4510c932728cf8144fb0e53070b5c19a
BLAKE2b-256 11957bb56bd6ac370ffd4d12ab0c3fec3d4e8571f28c7968be5d2c78f5acdbfa

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09c6cdd85976c1d8b8064481ec581d72efaa52eeff232e479454c412260d26e9
MD5 3306e8a8a1d6e50f4cf1ae11e4f87ce0
BLAKE2b-256 242fef5fcf3a32a5f027eb007f60b1b70b9d20f314a02318bec3e34ee1564b0a

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp38-cp38-macosx_10_16_x86_64.whl
Algorithm Hash digest
SHA256 dc6a974700a1273fffe0ceecb0f4e331d41c570a86047f89383811c94d7b9157
MD5 a2327115b5f037e187ffa3bd1774fa7a
BLAKE2b-256 718548d496dde1bcca8083cc800e05e2729e3d623023bef292984c5e8319e6b1

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for psygnal-0.10.2-cp38-cp38-macosx_10_16_arm64.whl
Algorithm Hash digest
SHA256 3ace1fa396190e3a08c8a8f3e9d59c030535987d59950da19589c6003a0b02f6
MD5 0cfd9f7f3b37c7ce46a92c8b7fd48f00
BLAKE2b-256 6dd3b77b8422341fb8d8216db19f781fea5b7ee859fc8ea3a52e7bd2b989f3e6

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