Name | py-pg-notify JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Simplifies listening to and sending notifications using PostgreSQL's LISTEN/NOTIFY functionality |
upload_time | 2024-12-14 07:58:43 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2024 DSSanjaya5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
postgresql
listen
notify
python
database
notification
postgres
|
VCS |
|
bugtrack_url |
|
requirements |
asyncpg
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# py-pg-notify
**py-pg-notify** is a Python library that simplifies listening to and sending notifications using PostgreSQL's `LISTEN/NOTIFY` functionality. This package leverages `asyncpg` for asynchronous communication with the database, making it ideal for real-time applications.
---
## ๐ Features
- ๐ **PostgreSQL Notifications**: Easy-to-use interfaces for `LISTEN/NOTIFY`.
- ๐ **Asynchronous**: Fully asynchronous with support for multiple listeners and channels.
- ๐ฆ **Lightweight**: Built on top of `asyncpg`, offering high performance.
- โ๏ธ **Custom Handlers**: Define your notification handling logic dynamically.
---
## ๐ Installation
Install the package via pip:
```bash
pip install py-pg-notify
```
---
## Usage
### Notifier Example
```python
import asyncio
from py_pg_notify import Notifier
async def create_trigger_example():
# Define the Notifier class for PostgreSQL
notifier = Notifier(
user="<username>",
password="<password>",
host="<host>",
port=5432,
dbname="<dbname>",
)
# Connect to the database
async with notifier:
# Create a trigger function for a channel
await notifier.create_trigger_function("notify_function", "ch_01")
# Create a trigger on a specific table that calls the function
await notifier.create_trigger(
table_name="my_table",
trigger_name="my_trigger",
function_name="notify_function",
event="INSERT",
)
# Retrieve and print existing trigger functions for a table
trigger_functions = await notifier.get_trigger_functions("my_table")
print("Existing Trigger Functions:", trigger_functions)
# Remove a trigger function
await notifier.remove_trigger_function("notify_function")
# Remove the trigger from the table
await notifier.remove_trigger("my_table", "my_trigger")
if __name__ == "__main__":
asyncio.run(create_trigger_example())
```
### Listener Example
```python
import asyncio
from py_pg_notify import Listener
async def notification_handler(connection, pid, channel, payload):
# Perform any processing on the received notification
print(f"Notification received: Channel={channel}, Payload={payload}")
async def main():
listener = Listener(
user="<username>",
password="<password>",
host="<host>",
port=5432,
dbname="<dbname>",
)
async with listener:
await listener.add_listener("ch_01", notification_handler)
await asyncio.sleep(3600) # Simulate long-running process
if __name__ == "__main__":
asyncio.run(main())
```
### Complete Example (Work In-Progress)
Refer to the examples/ folder for complete usage scenarios.
---
## ๐งช Testing
Run the test suite using pytest:
```bash
pip install -r requirements_test.txt
pytest --asyncio-mode=auto
```
---
## ๐ License
This project is licensed under the MIT License. See the LICENSE file for details.
---
## ๐ค Contributing
We welcome contributions! Please follow these steps:
1. Fork the repository.
2. Create a new branch.
3. Make your changes.
4. Add the test cases if needed.
5. Test all the test cases for verfication.
6. Submit a pull request.
---
## ๐ข Feedback and Support
For bugs or feature requests, create an issue in the GitHub repository. We'd love to hear your feedback!
Raw data
{
"_id": null,
"home_page": null,
"name": "py-pg-notify",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "postgresql, listen, notify, python, database, notification, postgres",
"author": null,
"author_email": "D S Sanjaya <dssanjay55555@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/1c/7d/d9a83eaaa078d34e1814f587bc500d41cc9d24e99a684a1584b47244e815/py_pg_notify-0.1.1.tar.gz",
"platform": null,
"description": "# py-pg-notify\r\n\r\n**py-pg-notify** is a Python library that simplifies listening to and sending notifications using PostgreSQL's `LISTEN/NOTIFY` functionality. This package leverages `asyncpg` for asynchronous communication with the database, making it ideal for real-time applications.\r\n\r\n---\r\n\r\n## \ud83d\udcd6 Features\r\n\r\n- \ud83d\udd0a **PostgreSQL Notifications**: Easy-to-use interfaces for `LISTEN/NOTIFY`.\r\n- \ud83d\udd04 **Asynchronous**: Fully asynchronous with support for multiple listeners and channels.\r\n- \ud83d\udce6 **Lightweight**: Built on top of `asyncpg`, offering high performance.\r\n- \u2699\ufe0f **Custom Handlers**: Define your notification handling logic dynamically.\r\n\r\n---\r\n\r\n## \ud83d\ude80 Installation\r\n\r\nInstall the package via pip:\r\n\r\n```bash\r\npip install py-pg-notify\r\n```\r\n\r\n---\r\n\r\n## Usage\r\n\r\n### Notifier Example\r\n```python\r\nimport asyncio\r\nfrom py_pg_notify import Notifier\r\n\r\n\r\nasync def create_trigger_example():\r\n # Define the Notifier class for PostgreSQL\r\n notifier = Notifier(\r\n user=\"<username>\",\r\n password=\"<password>\",\r\n host=\"<host>\",\r\n port=5432,\r\n dbname=\"<dbname>\",\r\n )\r\n\r\n # Connect to the database\r\n async with notifier:\r\n # Create a trigger function for a channel\r\n await notifier.create_trigger_function(\"notify_function\", \"ch_01\")\r\n\r\n # Create a trigger on a specific table that calls the function\r\n await notifier.create_trigger(\r\n table_name=\"my_table\",\r\n trigger_name=\"my_trigger\",\r\n function_name=\"notify_function\",\r\n event=\"INSERT\",\r\n )\r\n\r\n # Retrieve and print existing trigger functions for a table\r\n trigger_functions = await notifier.get_trigger_functions(\"my_table\")\r\n print(\"Existing Trigger Functions:\", trigger_functions)\r\n\r\n # Remove a trigger function\r\n await notifier.remove_trigger_function(\"notify_function\")\r\n\r\n # Remove the trigger from the table\r\n await notifier.remove_trigger(\"my_table\", \"my_trigger\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(create_trigger_example())\r\n```\r\n\r\n### Listener Example\r\n```python\r\nimport asyncio\r\nfrom py_pg_notify import Listener\r\n\r\n\r\nasync def notification_handler(connection, pid, channel, payload):\r\n # Perform any processing on the received notification\r\n print(f\"Notification received: Channel={channel}, Payload={payload}\")\r\n\r\n\r\nasync def main():\r\n listener = Listener(\r\n user=\"<username>\",\r\n password=\"<password>\",\r\n host=\"<host>\",\r\n port=5432,\r\n dbname=\"<dbname>\",\r\n )\r\n async with listener:\r\n await listener.add_listener(\"ch_01\", notification_handler)\r\n await asyncio.sleep(3600) # Simulate long-running process\r\n\r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(main())\r\n```\r\n\r\n### Complete Example (Work In-Progress)\r\nRefer to the examples/ folder for complete usage scenarios.\r\n\r\n---\r\n\r\n## \ud83e\uddea Testing\r\nRun the test suite using pytest:\r\n\r\n```bash\r\npip install -r requirements_test.txt\r\npytest --asyncio-mode=auto\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcc4 License\r\nThis project is licensed under the MIT License. See the LICENSE file for details.\r\n\r\n---\r\n\r\n## \ud83e\udd1d Contributing\r\nWe welcome contributions! Please follow these steps:\r\n\r\n1. Fork the repository.\r\n2. Create a new branch.\r\n3. Make your changes.\r\n4. Add the test cases if needed.\r\n5. Test all the test cases for verfication.\r\n6. Submit a pull request.\r\n\r\n---\r\n\r\n## \ud83d\udce2 Feedback and Support\r\nFor bugs or feature requests, create an issue in the GitHub repository. We'd love to hear your feedback!\r\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 DSSanjaya5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Simplifies listening to and sending notifications using PostgreSQL's LISTEN/NOTIFY functionality",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/DSSanjaya5/py-pg-notify"
},
"split_keywords": [
"postgresql",
" listen",
" notify",
" python",
" database",
" notification",
" postgres"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c38c51aea054725e1e33abd4c49f15b8e079a9035356703f6099598974d92d04",
"md5": "8c9ef6dd81e2f8e1f9145cf47e463186",
"sha256": "0b1cc6e1f2d680a3595a387d884673358564d7c60d50065d046e5b2790222aa7"
},
"downloads": -1,
"filename": "py_pg_notify-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8c9ef6dd81e2f8e1f9145cf47e463186",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 13211,
"upload_time": "2024-12-14T07:58:41",
"upload_time_iso_8601": "2024-12-14T07:58:41.568040Z",
"url": "https://files.pythonhosted.org/packages/c3/8c/51aea054725e1e33abd4c49f15b8e079a9035356703f6099598974d92d04/py_pg_notify-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1c7dd9a83eaaa078d34e1814f587bc500d41cc9d24e99a684a1584b47244e815",
"md5": "461daeaf98c01e951ba13508c2c8986e",
"sha256": "b756ac3187ab6bc8e2eafec88747da947e6e7ec8d38895b096aabee78d172982"
},
"downloads": -1,
"filename": "py_pg_notify-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "461daeaf98c01e951ba13508c2c8986e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 12046,
"upload_time": "2024-12-14T07:58:43",
"upload_time_iso_8601": "2024-12-14T07:58:43.917581Z",
"url": "https://files.pythonhosted.org/packages/1c/7d/d9a83eaaa078d34e1814f587bc500d41cc9d24e99a684a1584b47244e815/py_pg_notify-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-14 07:58:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "DSSanjaya5",
"github_project": "py-pg-notify",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "asyncpg",
"specs": [
[
"==",
"0.30.0"
]
]
}
],
"lcname": "py-pg-notify"
}