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")


listener = aiopg_listen.NotificationListener(aiopg_listen.connect_func())
listener_task = asyncio.create_task(
    listener.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.3 (2021-08-10)

  • Allow suppressing timeout by aiopg_listen.NO_TIMEOUT #9
  • Fix typing for python 3.8 #11

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiopg-listen-0.0.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for aiopg-listen-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c1372481939eb9169d4d999f2573ff1686f509e67bf50fdee96c94831fe6cdab
MD5 72da1f18ed770b6ad04c4408b39ab2f9
BLAKE2b-256 039afabebde9cf95ccac78f7cbe9432389104f4d71e7feb3fb451cbe02775b12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiopg_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.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for aiopg_listen-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fcba4cc7eae9093c283002a392ac1a54b4e6f0ebb77cb88ab77e37cdfdc7b049
MD5 7f47761ec6da4426f6834e1688306a7d
BLAKE2b-256 385dd112db42e0f2d00acd694ecc9b2b3406dc1061872d327b8368ec39401a9e

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