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.4 (2022-01-24)
v0.0.3 (2022-01-23)
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.4.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file asyncpg-listen-0.0.4.tar.gz
.
File metadata
- Download URL: asyncpg-listen-0.0.4.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 081d76b9d51b50e5461562af58ddbcc8821005d541ce5f3318afbe50fb6a8f91 |
|
MD5 | 7cf80d476d0c1ba53a21134bb1d2282a |
|
BLAKE2b-256 | 9ffe754bcbdea6fb6eb4f705d0013f4e0257a3a6d803d07b7f49ac1511de7798 |
File details
Details for the file asyncpg_listen-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: asyncpg_listen-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6b75d5a8c62d311cb05efdd8fa9778f4b760db64256f0a1135b074cf585a4a2 |
|
MD5 | 1e94627f4deda5e54f080fcf21a901e9 |
|
BLAKE2b-256 | d89d203b6b49c7a59df1d9d001ec38230b25f26a3944b381ac5ac864b6e8ec77 |