Skip to main content

Event Handling with Blink

Event handling library built on top of Blinker.

Why use it instead of blink

Pi-Blink is a different pardigm and a different way of handling events. So if Blink makes more sense then you should certainly use it. In the Pi-Blink paradigm events are created which can be listened, and modified, across your application.

Some other benefits are Priority-Based Event Handling: This script introduces the concept of event priorities, allowing you to specify the order in which event listeners should be executed. This can be useful when you have multiple listeners for the same event and need to control their execution sequence.

Installation

You can install pi-blink via pip:

pip install pi-blink

Basic Usage

Import

from pi_blink import blink

Create an event to listen to. This can be a class or primitive though classes are encouraged.

class MathEvent:
    def __init__(self, value: int):
        self.value = value

Set up listeners for the event.

@blink.listener(MathEvent)
def add3(event: MathEvent):
    event.value += 3


@blink.listener(MathEvent)
def multiply2(event: MathEvent):
    event.value *= 2

Create and send an event

e = MathEvent(1)
blink.send(e)
assert e.value == 8

Examples

Basic Example

from pi_blink import blink

class EventA:
    def __init__(self):
        self.order = []


@blink.listener(EventA)
def handle_event_a1(event : EventA):
    event.order.append("a1")


@blink.listener(EventA)
def handle_event_a2(event : EventA):
    event.order.append("a2")


if __name__ == "__main__":
    event_a = EventA()
    blink.send(event_a)
    assert event_a.order == ["a1", "a2"]

Basic Example with Priority

from pi_blink import blink

class EventA:
    def __init__(self):
        self.order = []


@blink.listener(EventA)
def handle_event_a1(event : EventA):
    event.order.append("a1")


@blink.listener(EventA, EventPriority.EARLY)
def handle_event_a2(event : EventA):
    event.order.append("a2")


if __name__ == "__main__":
    event_a = EventA()
    blink.send(event_a)
    assert event_a.order == ["a2", "a1"]

Release files for pi-blink 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pi-blink 1.0.3
File Size Uploaded
pi_blink-1.0.3.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pi-blink 1.0.3
File Interpreter ABI Platform
pi_blink-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page