Skip to main content

Easily LISTEN to PostgreSQL NOTIFY notifications

Project description

pgnotify: A python library to easily LISTEN to PostgreSQL NOTIFY notifications


LISTEN to and process NOTIFY events with a simple for loop, like so:

from pgnotify import await_pg_notifications

for notification in await_pg_notifications(
        ['channel1', 'channel2']):



Installable with any python package manager from the python package index, eg:

pip install pgnotify

All the bells and whistles

You can also handle timeouts and signals, as in this more fully-fleshed example:

import signal

from pgnotify import await_pg_notifications, get_dbapi_connection

# the first parameter of the await_pg_notifications
# loop is a dbapi connection in autocommit mode
CONNECT = "postgresql:///example"

# use this convenient method to create the right connection
# from a database URL
e = get_dbapi_connection(CONNECT)


for n in await_pg_notifications(
    ["hello", "hello2"],
    # the integer code of the signal is yielded on each
    # occurrence of a handled signal
    if isinstance(n, int):
        sig = signal.Signals(n)
        print(f"handling {}, stopping")

    # the `yield_on_timeout` option makes the
    # loop yield `None` on timeout
    elif n is None:
        print("timeout, continuing")

    # handle the actual notify occurrences here
        print((,, n.payload))

Further documentation to come.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pgnotify, version 0.1.1561372201
Filename, size File type Python version Upload date Hashes
Filename, size pgnotify-0.1.1561372201-py2.py3-none-any.whl (4.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pgnotify-0.1.1561372201.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page