Health check endpoint builder for web applications.
Project description
philiprehberger-health-check
Health check endpoint builder for web applications.
Installation
pip install philiprehberger-health-check
Usage
Basic Health Check
from philiprehberger_health_check import HealthCheck, checks
hc = HealthCheck()
hc.add("database", lambda: True)
hc.add(*checks.tcp("redis", "localhost", 6379))
hc.add(*checks.disk_space("disk", "/", min_free_gb=2))
result = hc.run()
print(result.status) # "healthy" or "unhealthy"
for check in result.checks:
print(f"{check.name}: {'OK' if check.healthy else check.message}")
Check Dependencies
hc = HealthCheck()
hc.add("database", check_db)
hc.add("migrations", check_migrations, depends_on=["database"])
result = hc.run()
# If "database" fails, "migrations" is skipped automatically
Async Execution
import asyncio
hc = HealthCheck()
hc.add("database", check_db)
hc.add("cache", check_cache)
hc.add("migrations", check_migrations, depends_on=["database"])
result = await hc.run_async()
# Independent checks run concurrently; dependencies are respected
Built-in Checks
# TCP connectivity
hc.add(*checks.tcp("postgres", "db.example.com", 5432, timeout=3))
# Disk space
hc.add(*checks.disk_space("storage", "/data", min_free_gb=5))
# Memory usage (Linux only, skipped on other platforms)
hc.add(*checks.memory("ram", max_percent=85))
# Custom check
hc.add(*checks.custom("cache", lambda: cache.ping()))
API
| Name | Description |
|---|---|
HealthCheck() |
Create a health check builder |
hc.add(name, fn, depends_on=None) |
Register a check with optional dependencies |
hc.run() |
Run all checks sequentially and return HealthResult |
hc.run_async() |
Run checks concurrently, respecting dependency order |
checks.tcp(name, host, port, timeout=2) |
TCP connectivity check |
checks.disk_space(name, path, min_free_gb=1) |
Disk free space check |
checks.memory(name, max_percent=90) |
Memory usage check (Linux) |
checks.custom(name, fn) |
Wrap any callable as a check |
CheckResult |
Dataclass: name, healthy, message, duration_ms |
HealthResult |
Dataclass: status, checks, uptime_seconds |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this package useful, consider starring the repository.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_health_check-0.2.0.tar.gz.
File metadata
- Download URL: philiprehberger_health_check-0.2.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f04393a959948cb8b119dd9f0ce4b016c5a37bce1bd375953cb609b6582ef6f
|
|
| MD5 |
765d216eae2cdf8c68086abca44271fa
|
|
| BLAKE2b-256 |
06fe293166525f308c9e45a83b46c7740e1a77ccdea1e7caee63b985447c70b0
|
File details
Details for the file philiprehberger_health_check-0.2.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_health_check-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eed5ff11addd6637ab259b16406d10298bd2dc52f063dafeba34c56314b11de5
|
|
| MD5 |
98b4659560e7a6c32d1a8f905353cc7a
|
|
| BLAKE2b-256 |
d61bdafe97548dc5a58274dc0fdc1fcb97524cbdacdc01a0fdf88cae943dd224
|