Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T18:04:41.000Z (over 1 year ago)
- Last Synced: 2024-10-29T04:46:50.933Z (about 2 months ago)
- Topics: asyncio, pubsub, python36
- Language: Python
- Homepage: http://aiopubsub.rtfd.io
- Size: 351 KB
- Stars: 10
- Watchers: 1
- 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/masterA 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 += 1async 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