What this is about
The last step of every monitoring pipeline is the notification: the collector has fetched feeds, the classifier has filtered them, and now your phone should buzz. Many people reach for a Telegram bot. That works, but it requires a bot token, a chat ID and either a library or your own code for the API.
ntfy.sh takes a different route. A topic is just a name. Anyone who sends an HTTP POST to that topic triggers a push notification on every device that subscribed to it. There is no bot, no registration and no chat.
How ntfy works
You pick a topic name, subscribe to it in the ntfy app and send messages by HTTP to the server address followed by the topic. The request body is the message text. Title, priority and tags travel as headers.
curl -H "Title: Heartbeat" \
-H "Priority: default" \
-H "Tags: white_check_mark" \
-d "Pipeline läuft, 3 neue Meldungen" \
ntfy.example.org/mein-topic
The hostname in the example is a placeholder. You can use the public service or run your own server.
Using it from Python
Inside the pipeline a single function call is enough. A timeout and an error path matter, so that an outage of the push service does not block processing.
import logging
import requests
log = logging.getLogger("notify")
def push(base_url: str, topic: str, text: str,
title: str = "", priority: int = 3, tags: str = "") -> bool:
headers = {"Priority": str(priority)}
if title:
headers["Title"] = title
if tags:
headers["Tags"] = tags
try:
r = requests.post(f"{base_url}/{topic}", data=text.encode("utf-8"),
headers=headers, timeout=10)
r.raise_for_status()
return True
except requests.RequestException as exc:
log.warning("ntfy nicht erreichbar: %s", exc)
return False
The return value False lets the caller retry the message later or fall back to a second channel such as email.
Using priorities and tags
ntfy has five priority levels. A fixed mapping works well: routine messages get the default level, real alarms the highest, and the daily heartbeat the lowest so that it does not ring. Tags are shown as emojis and help you tell messages apart at a glance.
One topic per purpose keeps subscriptions tidy: one for alarms, one for the heartbeat, one for information. That way each topic can be muted separately on the phone.
Access protection
A topic is not a secret, only a name. On a public server anyone who guesses it can read and write. For harmless messages that is acceptable, for anything else it is not. Three measures help:
- Use a long, random topic name and treat it like a password.
- Keep sensitive content out of the text. Send a short note and a hint where the details are stored.
- Run your own server with access rules and login when you need more protection.
Like any secret, the topic name belongs in an environment file and not in the code.
Limits compared to Telegram
ntfy is a one-way street: it sends messages, but you cannot reply in a chat or send commands to the pipeline. If you need follow-up questions, buttons or confirmations, a bot is the better tool. In return you get rid of token management, bot API rate limits and the dependency on a single provider.
Delivery differs too. With a self-hosted server it depends on how the phone handles push services. Check once, deliberately, that messages also arrive when power saving is active.
When it is worth it (and when not)
ntfy is worth it when your pipeline only needs to send: alarms, status messages, heartbeats. The effort is minimal, the code is short, and there is no bot that can expire or get blocked.
Stay with Telegram if you want to work interactively, for example acknowledge messages with a button or send commands. A sensible middle path is a dispatcher with several backends: ntfy as the default, Telegram or email as the fallback channel.