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")
async def main():
listener = asyncpg_listen.NotificationListener(asyncpg_listen.connect_func(user="postgres"))
listener_task = asyncio.create_task(
listener.run(
{"simple": handle_notifications},
policy=asyncpg_listen.ListenPolicy.LAST,
notification_timeout=5
)
)
await asyncio.sleep(1)
connection = await asyncpg.connect(user="postgres")
try:
for i in range(42):
await connection.execute(f"NOTIFY simple, '{i}'")
finally:
await connection.close()
await asyncio.sleep(1)
listener_task.cancel()
asyncio.run(main())
v0.0.7 (2024-09-07)
- Support python 3.12 and end support of 3.8
- End support of python 3.9 and 3.10
- Eagerly start notification processing with Python 3.12+
- Switch to asyncio.TaskGroup
v0.0.6 (2022-11-02)
v0.0.5 (2022-05-23)
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.7.tar.gz
(7.5 kB
view details)
Built Distribution
File details
Details for the file asyncpg-listen-0.0.7.tar.gz
.
File metadata
- Download URL: asyncpg-listen-0.0.7.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33d8c6a69bb20139d143fd9e4035a4627ac76fbea4d874529f99fbb33f0596c5 |
|
MD5 | 600866a71fd334acc3a67da3e1d84127 |
|
BLAKE2b-256 | a215092788b04358374dbff42288497f1acf6957aaa63267dda55bfda6d8b4c9 |
File details
Details for the file asyncpg_listen-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: asyncpg_listen-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6adb7a3394dbedd97ccd51109835cfd8cef6bd3c419387cf2eb8d9816c77361c |
|
MD5 | b5cc56abe0aa7de9140d55470c83ae2c |
|
BLAKE2b-256 | a8efee0e57219a04616d8c133a4602f805edadf64b95ba61f53fea1284948ba8 |