Skip to content

Send a push notification to your phone from Python

A few lines of Python send a notification to your Android phone when a script finishes, fails or stops running. requests or the standard library, no SDK and no API key.

Free to start, no ads. Android 7 and up.

When a script finishes

One POST from Python

Install anypush on your Android phone, make a channel and copy its address into an environment variable, ANYPUSH_URL. Then POST to it at the end of your script. The body is the message; JSON adds a title, a priority and a link to open when you tap it. The answer is 202 with the message's id.

JSON
message (required), title, priority (low, normal or high), url.
Headers
Title, Priority and Click, the same names ntfy uses. X-Title, X-Priority and X-Url work too.
Limits
A message up to 4,096 characters, a title up to 256, 64 KiB a request, 60 requests a minute per channel.
import os
import requests

r = requests.post(os.environ["ANYPUSH_URL"], data="Training finished: val_loss 0.231", timeout=10)
print(r.status_code, r.text)

202 {"duplicate":false,"id":977,"status_url":"https://anypush.app/h/your-token/messages/977"}

import os
import requests

r = requests.post(
    os.environ["ANYPUSH_URL"],
    json={
        "title": "train.py",
        "message": "Epoch 50/50 done, val_loss 0.231",
        "priority": "high",
        "url": "https://example.com/runs/42",
    },
    timeout=10,
)
print(r.status_code, r.text)

202 {"duplicate":false,"id":978,"status_url":"https://anypush.app/h/your-token/messages/978"}

import os
import urllib.request

req = urllib.request.Request(
    os.environ["ANYPUSH_URL"],
    data="Export done: 12,408 rows".encode(),
    headers={"Title": "nightly export"},
    method="POST",
)
with urllib.request.urlopen(req, timeout=10) as r:
    print(r.status, r.read().decode())

202 {"duplicate":false,"id":979,"status_url":"https://anypush.app/h/your-token/messages/979"}

When a scheduled script crashes, or stops running

Silent when it works, an alert when it fails

For a job that runs every hour or every night, a notification on every success is noise. Add the exit status to the address instead: 0 resets the channel's clock without a notification, and 1 to 255 is a high-priority alert with your text as its body. Give the channel a deadline in the app, and a job that stops running at all alerts you too.

Exit status
POST to the channel's address plus /0 to /255. 0 is a silent heartbeat; anything else arrives as "Exited with status N".
Repeats
The same status alerts at most once an hour, so a job that fails every five minutes buzzes once.
Silence
Set the channel to expect a message every hour, day or week. If nothing arrives in time, you get one alert.

job.py

import os
import traceback
import urllib.request

URL = os.environ["ANYPUSH_URL"]


def report(status, text=""):
    # 0 resets the channel's clock silently; 1-255 is an alert with the text as its body
    req = urllib.request.Request(f"{URL}/{status}", data=text.encode(), method="POST")
    with urllib.request.urlopen(req, timeout=10) as r:
        print(r.status, r.read().decode())


def main():
    ...  # your job here


try:
    main()
except Exception:
    report(1, traceback.format_exc()[-3000:])
    raise
else:
    report(0)

# a good run 202 {"heartbeat":true} # a run that raised KeyError 202 {"duplicate":false,"id":980} # the same failure again within the hour 202 {"duplicate":true,"id":980}

Tested on 29 November 2026

Each snippet above ran against a live channel on 29 November 2026, with Python 3.15.2 and requests 2.34.2; each answer is the real one, with the address shortened to your-token. The requests example arrived as a normal notification without a title. The JSON example arrived as a high-priority "train.py" notification that opens the link when tapped. The urllib example arrived with the title "nightly export". In job.py, the good run sent nothing to the phone and moved the channel's clock; the run that raised KeyError arrived as "Exited with status 1", high priority, with the traceback as the text; the same failure a second later was answered as a duplicate and did not buzz again.

Questions

Is there a pip package?

No, and none is needed: requests or urllib is enough. The package called anypush on PyPI is an unrelated project, so do not install it for this.

Do I need an API key?

No. The channel's address is the key: anyone who has it can send to your phone, so keep it in an environment variable or a secret, not in code you share. If it leaks, the app gives the channel a new address and the old one stops working at once.

Will a crash loop flood my phone?

No. With the exit status in the address, the same status alerts at most once an hour. Plain messages are limited to 60 a minute per channel.

Can I get a notification when a Jupyter cell or a training run finishes?

Yes. Put the requests line in the last cell, or after your training loop. Send the final metrics as the text and the dashboard's address as the url, and tapping the notification opens it.

Does it work on an iPhone?

No. anypush is an Android app, Android 7 and up.

Get anypush

Free to start, no ads. Android 7 and up.