Sign in Home API docs Agent Sharing Privacy Support
Get Pling
iPhone app macOS agent (.dmg) Linux Windows GitHub

Home / Docs / Python

Send push notifications from Python

Long training run, nightly ETL, or a script that sometimes throws at 3am? Send yourself an iPhone push from Python with a single requests.post to the Pling API. Below: a one-liner, a reusable helper, notify-on-exception, a no-dependency standard-library version, and Django and Flask hooks.

The minimal version

With requests, it is one call:

import requests

requests.post("https://api.plingpush.com/api/push", json={
    "token": "YOUR_TOKEN",
    "title": "Training finished",
    "message": "epoch 50, val_acc 0.94",
    "priority": "high",
})

A reusable helper

Read the token from the environment and wrap the call so the rest of your code stays clean:

import os, requests

def pling(title, message="", priority="normal", url=None):
    payload = {"token": os.environ["PLING_TOKEN"], "title": title,
               "message": message, "priority": priority}
    if url:
        payload["url"] = url
    requests.post("https://api.plingpush.com/api/push", json=payload, timeout=10)

pling("ETL complete", "12,418 rows loaded")

Notify me when it crashes

Wrap the job, push the exception, and re-raise so your logs still get the full traceback:

try:
    run_nightly_job()
except Exception as e:
    pling("Nightly job crashed", f"{type(e).__name__}: {e}", priority="high")
    raise

No dependencies (standard library)

If you cannot add requests, the built-in urllib works everywhere Python does:

import json, os, urllib.request

def pling(title, message="", priority="normal"):
    data = json.dumps({"token": os.environ["PLING_TOKEN"], "title": title,
                       "message": message, "priority": priority}).encode()
    req = urllib.request.Request("https://api.plingpush.com/api/push", data=data,
                                 headers={"Content-Type": "application/json"})
    urllib.request.urlopen(req, timeout=10)

Django and Flask error alerts

Push server errors to your phone the moment they happen. In Flask:

@app.errorhandler(500)
def on_error(e):
    pling("500 on the API", str(e), priority="high")
    return "Internal Server Error", 500

In Django, call the same helper from a logging handler or a custom 500 view so production exceptions reach your phone without waiting on email.

Where to get your token: create an API token in the Pling app, or at plingpush.com/account. The full reference, including channels and priorities, is in the API docs.

Frequently asked

Do I need the requests library?

No. requests is the most readable option, but the standard-library urllib.request version below has zero dependencies and is handy inside Docker images or restricted environments.

How do I get pinged when my script crashes?

Wrap the body in try / except and call the helper from the except block with the exception text, then re-raise. You get the traceback summary on your phone and still see the full crash in your logs.

Can I use this in Django or Flask?

Yes. Call the helper from a Django 500 handler or signal, or from a Flask errorhandler, to push server errors to your phone as they happen. See the example below.

Where do I keep the token?

Read it from an environment variable such as PLING_TOKEN rather than hardcoding it, and keep it out of version control.

More recipes: GitHub Actions · Cron jobs · full API reference