← 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

Send diagnostics (optional)

POST a short body (a log tail, row counts) and it's stored as the check-in's payload, handy when something looks off:

 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.