Skip to content

peajayni/pgevents

Repository files navigation

pgevents

Build Status Coverage Status Code style: black

Python event framework using PostgreSQL listen/notify

Example Usage

from pgevents import App

dsn = "dbname=test user=test password=test host=localhost"
channel = "foo"     # Postgres channel to listen for notifications on
topic = "bar"       # Event topic for handler to respond to

app = App(dsn, channel)


@app.register(topic)
def handler(context):
    print("Handling event")


app.run()

Create an event entry

INSERT INTO events (topic)
VALUES('bar');

Then send a notification by running the following SQL:

NOTIFY foo;