Skip to main content

Helps to use PostgreSQL listen/notify with asyncpg

Project description

asyncpg-listen

This library simplifies usage of listen/notify with asyncpg:

  1. Handles lost of a connection
  2. Simplifies processing notifications from multiple channels
  3. Setups a timeout for receiving a notification
  4. Allows to receive all notifications/only last notification depends 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.1 (2021-10-27)

  • 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

asyncpg-listen-0.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

asyncpg_listen-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file asyncpg-listen-0.0.1.tar.gz.

File metadata

  • Download URL: asyncpg-listen-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for asyncpg-listen-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cab48d46ccf84c6e476c9345f7f7ad97a610770e226f5eaecbe571fabd6c26a0
MD5 c0af8dd5ee3e248ae08a2ec7c8b4a379
BLAKE2b-256 9f40ef5ae97b116889ce14e2be681968dd2fce9901a786016575758d3a2a2351

See more details on using hashes here.

File details

Details for the file asyncpg_listen-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: asyncpg_listen-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for asyncpg_listen-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afe79edc9209c6b046940a5e47ad39c284bbc6f91eca84eb9ee3c533b8f325ae
MD5 1772f72d35c0e9a8538313bfaec8f0e5
BLAKE2b-256 5ea03ad425c807173005841ba559c9a2ceb128ec634ba0c099c00d98957c5ee2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page