Message service implementing publisher/subscriber pattern
Project description
APubSub
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)
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff18a0e6451caa0bdd0c0a40a7ee78922167b7b6e524419ba5d15932285f104b |
|
MD5 | 4b5ff2a285f94a9164782e99b981ade5 |
|
BLAKE2b-256 | de4841317e21aa94cae1ac49a91525692c8c1f1fc0f97f76762b2753ea8f04eb |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64808287f9df1f7972a84f7256efee743a6c2ff1b14470dbc06b203946fa01e1 |
|
MD5 | 052f0dd9a601f32c97d808dac0e05c8c |
|
BLAKE2b-256 | c2cc88a92481363465d3bc810423f6bb5e23e416629c609811e0c65ee5027fbd |