Asynchronous client library for the ntfy pub-sub notification service
-
Full Documentation: https://tr4nt0r.github.io/aiontfy
-
Source Code: https://github.com/tr4nt0r/aiontfy
You can install aiontfy via pip:
pip install aiontfy
"""Publish to a ntfy topic."""
from aiohttp import ClientSession
from aiontfy import Message, Ntfy
async with ClientSession() as session:
ntfy = Ntfy("https://ntfy.sh", session)
message = Message(
topic="aiontfy",
title="Hello",
message="World",
click="https://example.com/",
delay="10s",
priority=3,
tags=["octopus"],
)
print(await ntfy.publish(message))
"""Subscribe to ntfy topics."""
import asyncio
from aiohttp import ClientSession
from aiontfy import Event, Notification, Ntfy
def callback(message: Notification) -> None:
"""Process notifications callback function."""
if message.event is Event.MESSAGE:
print(message.to_dict())
async def main() -> None:
async with ClientSession() as session:
ntfy = Ntfy("https://ntfy.sh", session)
await ntfy.subscribe(
["aiontfy", "test"], # Subscribe to multiple topics
callback,
priority=[3, 4, 5], # Only subscribe to priority >= 3
)
asyncio.run(main())
For more advanced usage, refer to the [documentation](https://tr4nt0r.github.io/pynecil).
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch.
- Make your changes and commit them.
- Submit a pull request.
Make sure to follow the contributing guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find this project useful, consider buying me a coffee ☕ or sponsoring me on GitHub!