← All guides

Guide · Python

Monitor a Python script or job

A check-in is one HTTP request, so it's a couple of lines with requests, or with the standard library if you can't add a dependency.

1. Create a check

Create a check in Mortemain and copy its unique ping URL.

2. Ping around your work

Ping the URL on success, and the /fail endpoint on any exception so a crash forces the check down immediately.

 job.py
import requests

URL = "https://ping.mortemain.com/your-check-uuid"

try:
    run_nightly_etl()                       # your work
    requests.get(URL, timeout=10)           # success
except Exception:
    requests.get(URL + "/fail", timeout=10)  # failure
    raise

3. No requests? Use the standard library

Nothing to install, works on a bare Python:

 job.py
from urllib.request import urlopen

URL = "https://ping.mortemain.com/your-check-uuid"
urlopen(URL, timeout=10)                     # ping on success

POST works too (optional)

A POST is accepted just like a GET, so you can point an existing call at the ping URL without changing its method. We don't keep the body: a check-in records that your job ran, not what it printed.

 job.py
requests.post(URL, data=f"loaded {rows} rows in {secs}s", timeout=10)

Test it

Run the ping once. The check flips to up within a second or two; miss its window and you'll get the down alert.