Skip to content

A generic interface wrapping multiple backends to provide a consistent pubsub API.

License

Notifications You must be signed in to change notification settings

theruziev/aio_pubsub

Folders and files

NameName
Last commit message
Last commit date
Apr 29, 2021
Jul 21, 2021
Feb 21, 2021
Sep 23, 2019
Jul 16, 2021
Nov 1, 2018
Feb 21, 2021
Nov 1, 2018
Dec 15, 2018
Feb 15, 2023
Feb 15, 2023
Feb 21, 2021
Feb 20, 2021
Dec 15, 2018
Oct 20, 2021
Sep 23, 2019

Repository files navigation

AioPubSub

https://travis-ci.com/theruziev/aio_pubsub.svg?branch=master

A generic interface wrapping multiple backends to provide a consistent pubsub API.

Installation

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

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

About

A generic interface wrapping multiple backends to provide a consistent pubsub API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published