Helps to use PostgreSQL listen/notify with asyncpg
Project description
asyncpg-listen
This library simplifies usage of listen/notify with asyncpg:
- Handles loss of a connection
- Simplifies notifications processing from multiple channels
- Setups a timeout for receiving a notification
- Allows to receive all notifications/only last notification depending on ListenPolicy.
import asyncio
import asyncpg
import asyncpg_listen
async def handle_notifications(notification: asyncpg_listen.NotificationOrTimeout) -> None:
print(f"{notification} has been received")
listener = asyncpg_listen.NotificationListener(asyncpg_listen.connect_func())
listener_task = asyncio.create_task(
listener.run(
{"channel": handle_notifications},
policy=asyncpg_listen.ListenPolicy.LAST,
notification_timeout=1
)
)
async with asyncpg.connect() as connection:
for i in range(42):
await connection.execute(f"NOTIFY simple, '{i}'")
v0.0.2 (2021-11-02)
v0.0.1 (2021-10-27)
- A first version
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asyncpg-listen-0.0.2.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for asyncpg_listen-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a846bc5316713473b0f4a5dd9c48f9ecfa330640a76fbcfcf0b340f126df4a8 |
|
MD5 | 17edc6e9cd3f91bbc9602c8ba5499c7d |
|
BLAKE2b-256 | 7c3328e72db7fbe6ca23b9ee228b63ffbc333750866e95eb9ce8e37d47173472 |