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.5.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

apubsub-0.2.5-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apubsub-0.2.5.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.7.6 Linux/5.3.0-1029-gcp

File hashes

Hashes for apubsub-0.2.5.tar.gz
Algorithm Hash digest
SHA256 ff18a0e6451caa0bdd0c0a40a7ee78922167b7b6e524419ba5d15932285f104b
MD5 4b5ff2a285f94a9164782e99b981ade5
BLAKE2b-256 de4841317e21aa94cae1ac49a91525692c8c1f1fc0f97f76762b2753ea8f04eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apubsub-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.2 CPython/3.7.6 Linux/5.3.0-1029-gcp

File hashes

Hashes for apubsub-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 64808287f9df1f7972a84f7256efee743a6c2ff1b14470dbc06b203946fa01e1
MD5 052f0dd9a601f32c97d808dac0e05c8c
BLAKE2b-256 c2cc88a92481363465d3bc810423f6bb5e23e416629c609811e0c65ee5027fbd

See more details on using hashes here.

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