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

Uploaded Source

Built Distribution

apubsub-0.2.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apubsub-0.2.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.2 CPython/3.7.5 Linux/5.0.0-1026-gcp

File hashes

Hashes for apubsub-0.2.1.tar.gz
Algorithm Hash digest
SHA256 50af3f283b87d0770e131de0e12951f61387a876f5a5deb75a367911de75f52d
MD5 dbd7848c8093d530e06c2687c0b75730
BLAKE2b-256 3232b3278c94deb60d65c1e5270d5dabca1f0713b1bc5dc1d86939de5b833b27

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: apubsub-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.2 CPython/3.7.5 Linux/5.0.0-1026-gcp

File hashes

Hashes for apubsub-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90479e805783d3ab6c8207e1fd565c1a1aac38117317448bfe030509b59a9415
MD5 1ff9f9ef5fd78bb388a6b9b1f601202d
BLAKE2b-256 612b003915ea51a4580a9f50e606018ceb6f2ccb93bf2982ba71e6dd5d605e40

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