Skip to main content

Structured, UUID-based signal orchestration utilities for Python using Blinker

Project description

SignalKit

SignalKit is a lightweight Python signaling library built upon the robust Blinker library. It provides a simple yet flexible way to dispatch signals and handle responses, automatically adapting to your handler function signatures.

Installation

pip install signalkit

Usage Example

Synchronous

from signalkit import CoolSignal

class Event:
    def __init__(self, text: str):
        self.text = text

def handle_event(sender, event: Event) -> str:
    return event.text.upper()

def handle_payload(payload):
    return payload.upper()

signal = CoolSignal()
signal.connect(handle_event)
signal.connect(handle_payload)

event = Event("hello world")
print(signal.send(event=event))  # 'HELLO WORLD'
print(signal.emit("hello emit"))  # 'HELLO EMIT'

Asynchronous

from signalkit import CoolSignalAsync
import asyncio

class Event:
    def __init__(self, text: str):
        self.text = text

async def handle_event_async(sender, event: Event) -> str:
    return event.text.upper()

async def handle_payload_async(payload):
    return payload.upper()

signal = CoolSignalAsync()
signal.connect(handle_event_async)
signal.connect(handle_payload_async)

async def main():
    event = Event("hello async")
    print(await signal.send(event=event))  # 'HELLO ASYNC'
    print(await signal.emit("hello async emit"))  # 'HELLO ASYNC EMIT'

asyncio.run(main())

Benchmark Results

------------------------------------------------------------------------------------------------- benchmark: 10 tests -------------------------------------------------------------------------------------------------
Name (time in us)                                     Min                 Max               Mean            StdDev             Median               IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_signal_performance_with_exception             3.2000 (1.0)       66.5000 (1.81)      3.8896 (1.0)      1.5917 (1.0)       3.6000 (1.0)      0.3000 (1.50)    1915;4411      257.0982 (1.0)       69931           1
test_signal_performance_varied_handlers[1000]      3.4000 (1.06)     113.4000 (3.08)      3.9687 (1.02)     1.7224 (1.08)      3.7000 (1.03)     0.2000 (1.0)     2120;7051      251.9693 (0.98)      85471           1
test_signal_performance_varied_handlers[100]       3.4000 (1.06)     163.3000 (4.44)      4.1366 (1.06)     2.2271 (1.40)      3.8000 (1.06)     0.2000 (1.00)    3044;7284      241.7465 (0.94)      84746           1
test_signal_performance_varied_handlers[10]        3.4000 (1.06)     236.3000 (6.42)      4.1971 (1.08)     2.2533 (1.42)      3.8000 (1.06)     0.4000 (2.00)    3060;5749      238.2570 (0.93)      79366           1
test_signal_performance_varied_handlers[1]         3.4000 (1.06)     154.3000 (4.19)      4.2039 (1.08)     2.2521 (1.41)      3.8000 (1.06)     0.3000 (1.50)    3463;6809      237.8722 (0.93)      85471           1
test_signal_performance                            3.9000 (1.22)      36.8000 (1.0)       4.8123 (1.24)     2.4681 (1.55)      4.2000 (1.17)     0.4000 (2.00)      523;909      207.7994 (0.81)      11099           1
test_signal_performance_with_return                4.4000 (1.38)     160.9000 (4.37)      5.4575 (1.40)     2.8904 (1.82)      4.9000 (1.36)     0.4000 (2.00)    3086;6667      183.2346 (0.71)      74627           1
test_signal_disconnect_performance                11.5000 (3.59)     231.0000 (6.28)     14.4356 (3.71)     4.9942 (3.14)     13.0000 (3.61)     1.4000 (7.00)    2926;5351       69.2731 (0.27)      40323           1
test_signal_connect_performance                   13.8000 (4.31)     230.1000 (6.25)     16.5758 (4.26)     5.7558 (3.62)     15.1000 (4.19)     1.0000 (5.00)    1259;2324       60.3287 (0.23)      19084           1
test_signal_performance_large_payload             21.6000 (6.75)      87.6000 (2.38)     25.2284 (6.49)     6.4509 (4.05)     22.8000 (6.33)     2.3000 (11.50)     316;425       39.6378 (0.15)       3178           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean

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

signalkit-2.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

signalkit-2.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file signalkit-2.1.0.tar.gz.

File metadata

  • Download URL: signalkit-2.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for signalkit-2.1.0.tar.gz
Algorithm Hash digest
SHA256 ed5c9740774cd363e607de01d4bcf07a43b81c0642d7a94841d906f7266d387d
MD5 3b71da2715041995c3ca807212394196
BLAKE2b-256 8379d8b3021c5a3b7863a72e9f9f730ade063a29502ece5e7c3c6cca3e05591d

See more details on using hashes here.

File details

Details for the file signalkit-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: signalkit-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for signalkit-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5cf0630f8c3495f76e1e22b4682a34111fd309d853797cb9433ab4048a4131f
MD5 81fb08f7619d609122755f4ef88e7fc8
BLAKE2b-256 c747448352df9734e5c4af05965368d91e690ea7a71ab7c0bc235f6cb85717ae

See more details on using hashes here.

Supported by

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