https://github.com/theruziev/aio_pubsub
A generic interface wrapping multiple backends to provide a consistent pubsub API.
https://github.com/theruziev/aio_pubsub
asyncio pubsub python36
Last synced: 12 months ago
JSON representation
A generic interface wrapping multiple backends to provide a consistent pubsub API.
- Host: GitHub
- URL: https://github.com/theruziev/aio_pubsub
- Owner: theruziev
- License: mit
- Created: 2018-11-01T06:13:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T18:04:41.000Z (about 3 years ago)
- Last Synced: 2025-04-02T07:15:24.370Z (about 1 year ago)
- Topics: asyncio, pubsub, python36
- Language: Python
- Homepage: http://aiopubsub.rtfd.io
- Size: 351 KB
- Stars: 11
- Watchers: 0
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
AioPubSub
=========
.. image:: https://travis-ci.com/theruziev/aio_pubsub.svg?branch=master
:target: https://travis-ci.com/theruziev/aio_pubsub
.. image:: https://codecov.io/gh/theruziev/aio_pubsub/branch/master/graph/badge.svg
:target: https://codecov.io/gh/theruziev/aio_pubsub/branch/master
A generic interface wrapping multiple backends to provide a consistent pubsub API.
Installation
------------
.. code-block:: bash
pip install aio-pubsub
# for redis backend
pip install aio-pubsub[aioredis]
# for postgresql backend
pip install aio-pubsub[aiopg]
Usage
------
To use it, you need to implement your pubsub implementation from interfaces or use backends
from ``aio_pubsub.backends`` package
.. code-block:: python
import asyncio
from aio_pubsub.backends.memory import MemoryPubSub
pubsub = MemoryPubSub()
async def sender():
"""Publish a new message each second"""
counter = 0
while True:
await pubsub.publish("a_chan", "hello world %s !" % counter)
await asyncio.sleep(1)
counter += 1
async def receiver():
"""Print all message received from channel"""
subscriber = await pubsub.subscribe("a_chan")
async for message in subscriber:
print("Received message: '%s'" % message)
loop = asyncio.get_event_loop()
loop.run_until_complete(
asyncio.gather(sender(), receiver())
)
loop.close()
Supported backends
---------------------
``Disclaimer``: I would not advise you to use this backend, because it is shown only for testing purposes.
Better develop your own implementation.
* memory
* redis
* postgresql
* mongodb