Helps to use PostgreSQL listen/notify with aiopg
Project description
aiopg-listen
This library simplifies usage of listen/notify with aiopg:
- Handles lost of a connection
- Simplifies processing notifications from multiple channels
- Setups a timeout for receiving a notification
- Allows to receive all notifications/only last notification depends on
ListenPolicy
.
import asyncio
import aiopg
import aiopg_listen
async def handle_notifications(notification: aiopg_listen.NotificationOrTimeout) -> None:
print(f"{notification} has been received")
listener = aiopg_listen.NotificationListener(aiopg_listen.connect_func())
listener_task = asyncio.create_task(
listener.run(
{"channel": handle_notifications},
policy=aiopg_listen.ListenPolicy.LAST,
notification_timeout=1
)
)
async with aiopg.connect() as connection, connection.cursor() as cursor:
for i in range(42):
await cursor.execute(f"NOTIFY simple, '{i}'")
v0.0.5 (2021-11-02)
v0.0.4 (2021-09-08)
- Reexport explicitly #18
v0.0.3 (2021-08-10)
v0.0.2 (2021-07-25)
- Add
aiopg_listen.connect_func
to simplify initialization #5 - Rename consumer to listener #6
- Do not crash if handler fails #7
v0.0.1 (2021-07-25)
- A first version
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
aiopg-listen-0.0.5.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for aiopg_listen-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eca1342401370106d9b7529f1403b5e484132d44d3c94b18226f93726251d2ac |
|
MD5 | 84bf0c71b8203c12fb6e8b24fa37d537 |
|
BLAKE2b-256 | d55179efcd454a45d2287d623ff120988cdcfdcb4be092aaf991a1d6c635f6c1 |