A simple Python command-line tool that pings public REST APIs, logs their HTTP status codes and response times, and reports a health summary.
- Check one or more URLs passed directly via
--urls, or load a list from a file - Logs results to both the console and a log file (
api_health.logby default) - Captures connection errors and timeouts gracefully (no crashes on bad hosts)
- Supports repeated check cycles on an interval (basic uptime monitoring)
- Exits with a non-zero status code if any endpoint is unhealthy, so it can be plugged into CI/CD pipelines or cron jobs
pip install -r requirements.txtCheck specific URLs:
python health_checker.py --urls https://api.github.com https://httpbin.org/status/500Check URLs listed in a file (one per line):
python health_checker.py --file urls.txtRepeat checks every 60 seconds, 5 times:
python health_checker.py --file urls.txt --interval 60 --repeat 5Custom timeout and log file:
python health_checker.py --file urls.txt --timeout 5 --log-file my_log.log2026-06-30 10:00:01 [INFO] Starting health checks for 4 URL(s).
2026-06-30 10:00:01 [INFO] https://api.github.com -> 200 OK (142.31 ms)
2026-06-30 10:00:02 [INFO] https://httpbin.org/status/200 -> 200 OK (98.04 ms)
2026-06-30 10:00:02 [WARNING] https://httpbin.org/status/500 -> 500 UNHEALTHY (101.22 ms)
2026-06-30 10:00:03 [INFO] https://jsonplaceholder.typicode.com/posts/1 -> 200 OK (88.76 ms)
2026-06-30 10:00:03 [INFO] Summary: 3/4 endpoints healthy
api-health-checker/
├── health_checker.py # main script
├── requirements.txt # dependencies
├── urls.txt # sample list of URLs to check
└── README.md
- Backend scripting and automation with Python
- HTTP request handling using the
requestslibrary - Structured error handling (timeouts, connection errors, bad status codes)
- CLI design with
argparse - Logging best practices (file + console handlers)