Skip to main content

pgnotify_u: Updated pgnotify module. A python library to easily LISTEN and NOTIFY with PostgreSQL notifications system

Example

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(
        'postgresql:///example',
        ['channel1', 'channel2']):

    print(notification.channel)
    print(notification.payload)

Example2

NOTIFY to:

from pgnotify import pg_notify
pg_notify("postgresql:///example", 'channel1', 'hello')

Install

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

pip install pgnotify_u

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)

SIGNALS_TO_HANDLE = [signal.SIGINT, signal.SIGTERM]

for n in await_pg_notifications(
    e,
    ["hello", "hello2"],
    timeout=10,
    yield_on_timeout=True,
    handle_signals=SIGNALS_TO_HANDLE,
):
    # 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 {sig.name}, stopping")
        break

    # 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
    else:
        print((n.pid, n.channel, n.payload))

Further documentation to come.

Download files

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

Source Distribution

pgnotify_u-0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgnotify_u-0.2-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pgnotify_u-0.2.tar.gz.

File metadata

  • Download URL: pgnotify_u-0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for pgnotify_u-0.2.tar.gz
Algorithm Hash digest
SHA256 9cd07550c5a7492522a06e56044cf4d31845fe2195e80e6795ff29608a29eef4
MD5 9952af276773d9fa9e42fd451e4a9dd8
BLAKE2b-256 0351d7c51b3b078b27bfa6b2e6d50ea84e9fcf67f00fca05b22d2df8ce2a65f7

See more details on using hashes here.

File details

Details for the file pgnotify_u-0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pgnotify_u-0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for pgnotify_u-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 640665a46df4dad66bd642590905b545afb9991e636d240d8fc42453a03bef2e
MD5 9a20e79afc7294c3adc6de61ee155d50
BLAKE2b-256 d829c2d78d37b8c1f86cbb3ec170a5ff81174ac867f6761e912d02b01961fc10

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page