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
ConsumePolicy
.
import asyncio
import aiopg
import aiopg_listen
from typing import Union
async def process_notifications(notification: Union[aiopg_listen.Notification, aiopg_listen.Timeout]) -> None:
print(f"{notification} has been received")
consumer = aiopg_listen.NotificationConsumer(aiopg.connect)
consume_task = asyncio.create_task(
consumer.consume(
{"channel": process_notifications},
policy=aiopg_listen.ConsumePolicy.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.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.1.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file aiopg-listen-0.0.1.tar.gz
.
File metadata
- Download URL: aiopg-listen-0.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4e418c1260dc7eba3f36b34f5fbea0fcc03dfbbdcd7a5671c5fff9117b151d6 |
|
MD5 | 4d3195e10a14033e4a2e762042ca000b |
|
BLAKE2b-256 | 1656e9fb5d57f76fead95a45040fb94b7ae27f86bba079ea221aab1426277a2b |
File details
Details for the file aiopg_listen-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiopg_listen-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af5c6cbca8857c68f806a9c4a845f748a09d05bbb8c45ff5646d9e491165c221 |
|
MD5 | edfbcdb7892d3dfe61b8dc7c3b88bf3f |
|
BLAKE2b-256 | a102377cc1503138e82581445c35ed0744d3b2a781d474d19a66d1663d691931 |