Skip to main content

Python implementation of the Event Pattern

Project description

Test Coverage Stable Version Pre-release Version PyPI - Python Version PyPI Downloads

delegate-events: Python implementation of the Event Pattern.

delegate-events provides a basic implementation of the well-known Event or Pub/Sub Pattern, and is built on top of the delegate-pattern package which handles the delegation part.

Example

from delegate.pattern import delegate
from delegate.events import Channel, Event

class OnSomethingEvent(Event):
    def __init__(self, what: str, why: str):
        self.what = what
        self.why = why

    def __str__(self):
        return f"{self.what} happened because of {self.why}"

class Class1:
    on_something = delegate(Channel[OnSomethingEvent])

inst = Class1()
msg_queue: list[Event] = []

def fn(publisher, event: OnSomethingEvent):
    msg_queue.append(event)

inst.on_something.subscribe(fn)
inst.on_something.fire(OnSomethingEvent("Something", "some other thing"))

str(msg_queue[0]) # => "Something happened because of some other thing"

Full documentation

Go to documentation

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

delegate_events-0.0.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

delegate_events-0.0.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file delegate_events-0.0.2.tar.gz.

File metadata

  • Download URL: delegate_events-0.0.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for delegate_events-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6c776c884276039de8b488eae7f76dfc6b94258781029dc41aaf580d0d584820
MD5 8690febb783cd7a7a11c3d6802a3a14b
BLAKE2b-256 b66fe876f43710a2c9b0dfaebf8f58f2cd57a716f8edb5072d77f3cf9e0bc8cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for delegate_events-0.0.2.tar.gz:

Publisher: python-publish.yml on apmadsen/delegate-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file delegate_events-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for delegate_events-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4618d053197ecbdf65d039222bb1b7d29e35bd42b86bace14cf6feda0356a72b
MD5 cf87d9bb1525ec926e422dc3b892e2e2
BLAKE2b-256 7fc8acb242bd7ab86973d9e5824c5fc609f1e0aa604b19f69415dc9c00c0498f

See more details on using hashes here.

Provenance

The following attestation bundles were made for delegate_events-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on apmadsen/delegate-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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