Send a Notification with Python
Use the Ntfy me HTTP endpoint to post a notification with small Python scripts that handle authentication. Provide your bearer token below to generate the ready-to-run examples.
Tokens must be at least 10 characters and may only include lowercase letters, numbers, and hyphens.
JSON payload with Authorization header
The example below publishes the message Test Message to the topic test using a JSON payload and Authorization header.
It uses only the Python standard library, so you can run it directly with python3 after pasting the script into a file.
The script sends the JSON payload, authenticates with a bearer token, and prints the JSON response in a readable format. JSON unlocks the full feature set of the app because it lets you control topics, message bodies, and optional metadata.
JSON payload with token field
Prefer this variant if you want to place the token inside the JSON payload instead of the Authorization header. The script keeps the request headers minimal and moves authentication into the JSON body.
Plain text payload
You can also send a plain text payload if you only need to publish a quick message.
This shortcut is convenient, but it omits JSON-specific fields. Prefer the JSON format if you want richer notifications.