A small, in-process message bus implementation.
Project description
mbuslite provides a message bus implementation embedded within the application’s process.
With it, you can loosely couple your application components. It implements the publish-subscribe pattern.
Motivation
Having worked with crossbar and autobahn, as well as DBus, I like the message bus pattern. I’ve wanted to use it in some projects to achieve the same loose coupling between internal components.
Having also worked wih sqlite, I like the simplicity of a library instead of a remote service.
Thus, mbuslite.
Installation
pip install mbuslite
Usage
To get started, import mbuslite.Bus and start calling .subscribe() and .publish().
from mbuslite import Bus
class Producer:
def announce( self ):
Bus.publish( 'topic.name', 'Hello, consumers!' )
class Consumer:
def __init__( self ):
Bus.subscribe( 'topic.name', self.on_message )
def on_message( self, msg ):
print( msg )
consumer1 = Consumer()
consumer2 = Consumer()
consumer3 = Consumer()
producer = Producer()
producer.announce()
Hello, consumers!
Hello, consumers!
Hello, consumers!
Publishers and subscribers must agree upon a call signature as the arguments are passed as-is by mbuslite.
def handler( one, two, three, four ):
pass
Bus.subscribe( 'foo', handler )
Bus.publish( 'foo', 1, 2, three = 3, four = 4 )
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.