Skip to main content

PostGreSQL LISTEN/NOTIFY functionality, via psycopg2

Project description

This package makes it simple to use PostGreSQL’s NOTIFY/LISTEN eventing system from Python in a consistent, pleasing manner.

Note that this project officially supports Python 3.6+. This is primarily due to static typing.


The following shows an example of the package in action.


  • PostGreSQL server is running locally.
  • default database (postgres) is available.
  • table exists in database in the public schema with the name orders.
from psycopg2 import connect
from psycopg2_pgevents.trigger import install_trigger, \
    install_trigger_function, uninstall_trigger, uninstall_trigger_function
from psycopg2_pgevents.event import poll, register_event_channel, \

connection = connect(dsn='postgres:///postgres')
connection.autocommit = True

install_trigger(connection, 'orders')

    print('Listening for events...')
    while True:
        for evt in poll(connection):
            print('New Event: {}'.format(evt))
except KeyboardInterrupt:
    print('User exit via Ctrl-C; Shutting down...')
    uninstall_trigger(connection, 'orders')
    print('Shutdown complete.')


  • The connection’s autocommit property must be enabled for this package to operate correctly. This requirement is provided by PostGreSQL’s NOTIFY/LISTEN mechanism.
  • The same connection that is used with register_event_channel() must be used with poll() in order to receive events. This is due to the nature of how PostGreSQL manages “listening” connections.
  • If the table that you’d like to listen to is not in the public schema, the schema name must be given as a keyword argument in the install_trigger() method.

Authorship and License

Written by Shawn Wallis and distributed under the MIT license.

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 psycopg2-pgevents, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size psycopg2_pgevents-0.2.2-py3-none-any.whl (10.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size psycopg2-pgevents-0.2.2.tar.gz (9.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page