{"id":17102092,"url":"https://github.com/djrobstep/pgnotify","last_synced_at":"2025-08-22T00:32:41.097Z","repository":{"id":54694067,"uuid":"87814121","full_name":"djrobstep/pgnotify","owner":"djrobstep","description":"Easily LISTEN to PostgreSQL NOTIFY messages","archived":false,"fork":false,"pushed_at":"2021-02-03T13:23:20.000Z","size":15,"stargazers_count":66,"open_issues_count":3,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-07T21:43:35.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djrobstep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-10T13:29:13.000Z","updated_at":"2024-08-27T15:31:31.000Z","dependencies_parsed_at":"2022-08-14T00:10:51.834Z","dependency_job_id":null,"html_url":"https://github.com/djrobstep/pgnotify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djrobstep%2Fpgnotify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djrobstep%2Fpgnotify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djrobstep%2Fpgnotify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djrobstep%2Fpgnotify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djrobstep","download_url":"https://codeload.github.com/djrobstep/pgnotify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542289,"owners_count":18242332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T15:28:09.413Z","updated_at":"2024-12-20T06:07:26.467Z","avatar_url":"https://github.com/djrobstep.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgnotify: A python library to easily LISTEN to PostgreSQL NOTIFY notifications\n\n## Example\n\nLISTEN to and process NOTIFY events with a simple `for` loop, like so:\n\n```python\nfrom pgnotify import await_pg_notifications\n\nfor notification in await_pg_notifications(\n        'postgresql:///example',\n        ['channel1', 'channel2']):\n\n    print(notification.channel)\n    print(notification.payload)\n```\n\n## Install\n\nInstallable with any python package manager from the python package index, eg:\n\n```shell\npip install pgnotify\n```\n\n## All the bells and whistles\n\nYou can also handle timeouts and signals, as in this more fully-fleshed example:\n\n```python\nimport signal\n\nfrom pgnotify import await_pg_notifications, get_dbapi_connection\n\n# the first parameter of the await_pg_notifications\n# loop is a dbapi connection in autocommit mode\nCONNECT = \"postgresql:///example\"\n\n# use this convenient method to create the right connection\n# from a database URL\ne = get_dbapi_connection(CONNECT)\n\nSIGNALS_TO_HANDLE = [signal.SIGINT, signal.SIGTERM]\n\nfor n in await_pg_notifications(\n    e,\n    [\"hello\", \"hello2\"],\n    timeout=10,\n    yield_on_timeout=True,\n    handle_signals=SIGNALS_TO_HANDLE,\n):\n    # the integer code of the signal is yielded on each\n    # occurrence of a handled signal\n    if isinstance(n, int):\n        sig = signal.Signals(n)\n        print(f\"handling {sig.name}, stopping\")\n        break\n\n    # the `yield_on_timeout` option makes the\n    # loop yield `None` on timeout\n    elif n is None:\n        print(\"timeout, continuing\")\n\n    # handle the actual notify occurrences here\n    else:\n        print((n.pid, n.channel, n.payload))\n```\n\nFurther documentation to come.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjrobstep%2Fpgnotify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjrobstep%2Fpgnotify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjrobstep%2Fpgnotify/lists"}