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)
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.
Metadata
Release files for pgnotify 0.1.1561372201
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pgnotify-0.1.1561372201.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pgnotify-0.1.1561372201-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / pgnotify-0.1.1561372201.tar.gz
| Download URL | pgnotify-0.1.1561372201.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
509dfe42fde26c6eab066698adc679cf026bf6d1a2feea0ed58d77f6c376ce99
|
|
BLAKE2b-256 checksum How to use checksums |
792301bc239fd97b399373b639a20f04082cb062fb566dd116f953d9c270f2a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.0 Linux/4.15.0-1035-aws
|
Release files / pgnotify-0.1.1561372201-py2.py3-none-any.whl
| Download URL | pgnotify-0.1.1561372201-py2.py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b9632f3b515f68ec872f1491abc7416391800c0c0c2d62c9b4fa49ebbc71297e
|
|
BLAKE2b-256 checksum How to use checksums |
bc0521fdd45e3c713c3ce893a12d6d05a6bd2fc52baa3f9404da673ef434d7d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.0 Linux/4.15.0-1035-aws
|