Skip to main content

Message service implementing publisher/subscriber pattern

Project description

APubSub

Build Status Coverage PyPI version GitHub

Simple, single-purpose message service implementation.

Installation

Python versin 3.7+ required

Just install it with pip: pip install apubsub

Usage

from apubsub import Service

service = Service()

# Note that service is started in stand-alone process
# so start it as early as possible to minimize resource pickling*
service.start()

class Klass:

    def __init__(self):
        self.sub = service.get_client()
        await self.sub.start_consuming()  # subscriber should be started
        
        self.pub = service.get_client()  # if used only as publisher, it is not required

    async def do_smth(self):
        data = await self.sub.get(.1)  # fetch received data with timeout
        if data is None:
            print("No data received by subscriber")
            return
        print(data)
    
    async def do_smth_else(self):
        msg = "some string data"
        await self.pub.publish("topic", msg)

    async def use_iter_get(self):
        async for data in self.sub.get_iter():
            print(f"Data received: {data}")

Check out more examples in tests

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 apubsub, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size apubsub-0.2.2-py3-none-any.whl (8.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size apubsub-0.2.2.tar.gz (7.1 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