Python client for Notipy Server
A Python client which talks to the Notipy Server-REST-API.
The following code snippet sends a Hello World message to the Telegram user with the username myuser.
from notipy import Notipy, BackendType
# Hostname and port of the notipy-server instance
HOST = "localhost"
PORT = 8000
notifier = Notipy(HOST, PORT)
notifier.send(BackendType.TELEGRAM, "myuser", "Hello World")
The client uses the Jinja2 Templating Engine to support templated messages.
All the parameters for Jinja2 can be passed as keyword arguments to the send_templated
function.
from pathlib import Path
from notipy import Notipy, BackendType
# Hostname and port of the notipy-server instance
HOST = "localhost"
PORT = 8000
# Template directory
TEMPLATE_DIR = Path("/var/lib/templates")
notifier = Notipy(HOST, PORT, template_dir=TEMPLATE_DIR)
notifier.send_templated(BackendType.TELEGRAMGROUP, "mygroup", "mytemplate", foo="bar")
Templates always have the file name suffix .tmpl
. The mytemplate.tmpl file in the /var/lib/templates directory
would look like this:
Hello {{ foo }}!
So mygroup would recive the message: Hello bar!
.