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.1.tar.gz (6.7 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.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for delegate_events-0.0.1.tar.gz
Algorithm Hash digest
SHA256 850459c424ad9afbe9f809b3052c7172f5713a7df3312613811a7e96467e57c6
MD5 5c5bb0a7cb5ef968fe09f5a5593d24e7
BLAKE2b-256 02698300af1d6f74dbf7073492b766ec4e5e61475f49d68870261eb84e53108c

See more details on using hashes here.

Provenance

The following attestation bundles were made for delegate_events-0.0.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for delegate_events-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd49b044f029a254cfd7eb53c42c787be0c11fdd5ce4ddf1d1e4ec2cc356f239
MD5 13d9b2098fe83b553445ccb02f117a4d
BLAKE2b-256 a31bc5d1a2c3b58fd18623f5946baead9f628604d2080b7e6ac7cff3a50ad69e

See more details on using hashes here.

Provenance

The following attestation bundles were made for delegate_events-0.0.1-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