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.

Source Distribution

apubsub-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

apubsub-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file apubsub-0.2.0.tar.gz.

File metadata

  • Download URL: apubsub-0.2.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.8.0 Windows/10

File hashes

Hashes for apubsub-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6d44d177bc2d0445ff3c62ea6e7ad59035280d5dd08204995ee492fe3bc71ca8
MD5 3e44b7f89a1f0e4ca4511b8f2beacfd6
BLAKE2b-256 3e7ca78a3a6c515a462d9bf22968479066d8a1c7b727c2c3822cd57585ec0cbd

See more details on using hashes here.

Provenance

File details

Details for the file apubsub-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: apubsub-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.8.0 Windows/10

File hashes

Hashes for apubsub-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb9f37a8947baa151a4b0cac331461ae8c6aad2f1a5bed53dcd8d9cec9ae55e6
MD5 e9e75652faaa474b906efa5a6af017eb
BLAKE2b-256 ee25a4e0251593c9f641c47ec5a2625bd1d9ac6ce7ace34b2b67fa5650e60d6f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page