Skip to main content

A library inspired by the Django Dispatch System for simple pub-sub interactions.

Project description

Simple Dispatch

Build Status codecov

A library inspired by the Django Dispatch System for simple pub-sub interactions. it is a low footprint and small library designed for resource constrained or high-efficiency systems with no dependencies.

Getting Starting

To install, pip install simple-dispatch or pipenv install simple-dispatch

Usage

Simple Example

from simple_dispatch import subscriber, dispatch

MY_EVENT = 'abc'

@subscriber(MY_EVENT)
def handle(**kwargs):
    print(kwargs)

def main():
    dispatch(MY_EVENT, a=1, b=2, c=3)

main()

# OUTPUT: {'a': 1, 'b': 2, 'c': 3}

Subscriber Listens to Multiple Events

from simple_dispatch import subscriber, dispatch

MY_EVENT = 'abc'
MY_SECOND_EVENT = 'xyz'

@subscriber(MY_EVENT, MY_SECOND_EVENT)
def handle(**kwargs):
    print(kwargs)

def main():
    dispatch(MY_EVENT, a=1, b=2, c=3)
    dispatch(MY_SECOND_EVENT, a=4, b=5, c=6)

main()

# OUTPUT: 
# {'a': 1, 'b': 2, 'c': 3}
# {'a': 4, 'b': 5, 'c': 6}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for simple-dispatch, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size simple_dispatch-1.1.0.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page