Skip to main content

Event Handling with Blink

Event handling library built on top of Blinker.

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"]

Metadata

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 Provenance Actions
pi_blink-1.0.3.tar.gz 6.7 kB Without provenance Details for pi_blink-1.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 14.1 kB

Security for pi-blink 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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