Skip to main content

Helps to use PostgreSQL listen/notify with aiopg

Project description

aiopg-listen

This library simplifies usage of listen/notify with aiopg:

  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 aiopg
import aiopg_listen


async def handle_notifications(notification: aiopg_listen.NotificationOrTimeout) -> None:
    print(f"{notification} has been received")


consumer = aiopg_listen.NotificationListener(aiopg_listen.connect_func())
consume_task = asyncio.create_task(
    consumer.run(
        {"channel": handle_notifications},
        policy=aiopg_listen.ListenPolicy.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.2 (2021-07-25)

  • Add aiopg_listen.connect_func to simplify initialization #5
  • Rename consumer to listener #6
  • Do not crash if handler fails #7

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

Uploaded Source

Built Distribution

aiopg_listen-0.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file aiopg-listen-0.0.2.tar.gz.

File metadata

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

Hashes for aiopg-listen-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c0341040cf3f03686071289b82fa83b3fdcfd004279bdb8b79dac03e530c4f3f
MD5 7268ec3395133c2fce7df5e42a2fee64
BLAKE2b-256 1c525af390a70012513d69d1504ee0c9d4ba32ff8ee83a40b8cfe48a55023777

See more details on using hashes here.

File details

Details for the file aiopg_listen-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: aiopg_listen-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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

Hashes for aiopg_listen-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87fde3675e6a8925aeab5fc6eb37efb017124568152447a275d1226c22c1ee38
MD5 e5d814ae9501ae1022d17808b47f49ee
BLAKE2b-256 65b7fbb31e13293a66cc093c2531168a802a1ced03ba17710dad7d9056b0c48e

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