Skip to main content

image image image image image image Actions status

PostgreSQL Notification Listener

This project is a Python library that listens to notifications from a PostgreSQL database. It provides a simple way to execute functions when specific events happen in the database.

How it works

The listener connects to the PostgreSQL database and sets up a notification channel. You can then attach callbacks to this channel, which will be executed whenever a notification is received. The listener tries to minimize the times callbacks are called. When there are multiple pending notifications on the same channel, the callback is called only once. This means that the notification payload and PID are ignored.

Installation

To install the library, run: pip install postgresql-notification-listener

Usage

To use this library, follow these steps:

  • Import the library in your Python script: from postgresql_notification_listener import NotificationListener
  • Create instance of the listener listener = NotificationListener("postgresql://localhost/postgres")
  • Define a callback function that will be executed when a notification is received.
  • Use the subscribe_to_channel method to attach your callback function to the notification channel: listener.subscribe_to_channel("channel_to_listen", callback_function)
  • You must register all callback functions before calling the start method.
  • You cannot unregister callback functions after calling the start method.
  • Start listening for notifications by calling the start method: listener.start()
  • You can trigger a notification from PostgreSQL by NOTIFY channel_to_listen statement.
  • The start method will call all attached callbacks once when called. If you don't want this behaviour, pass the initial_run=False argument to the start method: listener.start(initial_run=False)
  • NotificationListener can be used as a context manager: with NotificationListener("connection string") as listener:. The database connection automatically closes when exiting the with block.

API

  • NotificationListener: The main class of this library. It is responsible for setting up a notification channel and managing callbacks.
    • subscribe_to_channel : Attaches a callback function to a specific channel. The subscribe_to_channel method takes two required parameters: the name of the channel to listen to and the callback function to execute when a notification is received.
    • start : Starts listening for notifications. If you don't want all attached callbacks to be called once when called, pass initial_run=False as an argument. If you want to call all callback after X seconds if no notification is received, pass poll_interval=X.

Metadata

Release files for postgresql-notification-listener 3.2.6

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

Source distribution (sdist)

Source distribution for postgresql-notification-listener 3.2.6
File Size Uploaded Provenance Actions
postgresql_notification_listener-3.2.6.tar.gz 4.7 kB With provenance Details for postgresql_notification_listener-3.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for postgresql-notification-listener 3.2.6
File Interpreter ABI Platform Actions
postgresql_notification_listener-3.2.6-py3-none-any.whl Python 3 none any Details for postgresql_notification_listener-3.2.6-py3-none-any.whl

Total release size: 10.6 kB

Release files / postgresql_notification_listener-3.2.6.tar.gz

Download URL postgresql_notification_listener-3.2.6.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
60cd11327e867c1c37bc374689601e2b2d9938d92c7c7e0f827ab78860f858bd
BLAKE2b-256 checksum
How to use checksums
7529e591d8d9bcd58722adfb9bcc5891ce7e20a2d620db060333251f6aca4b80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / postgresql_notification_listener-3.2.6-py3-none-any.whl

Download URL postgresql_notification_listener-3.2.6-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7cd703d9b11bbc211886fae9aac1c9911b624b5b7790ff8e271f20031520df6
BLAKE2b-256 checksum
How to use checksums
11fa7d2142f88ac4803633b0757ae9c73464f206f3ed0e36969c61b71da631e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Security for postgresql-notification-listener 3.2.6

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for postgresql_notification_listener-3.2.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

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