Skip to main content

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

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)

Install

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)

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)
        if n in SIGNALS_TO_HANDLE:
            print(f"handling {sig.name}")
        print("interrupted, 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.

Metadata

Release files for pgnotify 0.1.1541160523

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgnotify 0.1.1541160523
File Size Uploaded Provenance Actions
pgnotify-0.1.1541160523.tar.gz 4.1 kB Without provenance Details for pgnotify-0.1.1541160523.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pgnotify 0.1.1541160523
File Interpreter ABI Platform Actions
pgnotify-0.1.1541160523-py2.py3-none-any.whl Python 3, Python 2 none any Details for pgnotify-0.1.1541160523-py2.py3-none-any.whl

Total release size: 11.8 kB

Release files / pgnotify-0.1.1541160523.tar.gz

Download URL pgnotify-0.1.1541160523.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
80b8c84c4fe51dc9609ea09fafd3b97ffbd8632b449d8e3ad28441fa1ecfdd12
BLAKE2b-256 checksum
How to use checksums
b6803865ca70dd908306a0b19a386ccc1008e3165e43d26549d5b294eade3fbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.5 CPython/3.7.0 Linux/4.4.0-137-generic

Release files / pgnotify-0.1.1541160523-py2.py3-none-any.whl

Download URL pgnotify-0.1.1541160523-py2.py3-none-any.whl
Size 7.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f93bad832a582640b8e25695e2c723553a73f6bcbc810c34e0f7ebbf69cc4e42
BLAKE2b-256 checksum
How to use checksums
c35db310be8ce4c9fab9b7ee2c6201a832a6738694e470052c50ac04d7d24a78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.5 CPython/3.7.0 Linux/4.4.0-137-generic

Security for pgnotify 0.1.1541160523

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page