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 loss of a connection
  2. Simplifies notifications processing from multiple channels
  3. Setups a timeout for receiving a notification
  4. 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.3 (2022-01-23)

v0.0.2 (2021-11-02)

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.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: asyncpg-listen-0.0.3.tar.gz
  • Upload date:
  • Size: 4.9 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.1

File hashes

Hashes for asyncpg-listen-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5f88664d71199169bada3cc55d5c35b06060f196a325ab94c5c57036a6a04b6a
MD5 d181f12866f8ec3c94e26ba491df4dd0
BLAKE2b-256 a318332cd63cc6ecfc18f5a3c8b9f6156e1c502c9495f11fa94e2825fd829522

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncpg_listen-0.0.3-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.1

File hashes

Hashes for asyncpg_listen-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9be47b730ea5751f98fb81b73a2729baf54cc2cee69e9fcd84c4239d23f2ca83
MD5 837becbc2bf1f8746f46ab546b599ae0
BLAKE2b-256 2fc33e00cb7397696292a33c61ae42faa0e88887ded7c7845a5f984229be2e83

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