healthkit
Professional health checks for FastAPI -- DB, Redis, disk, memory in one endpoint.
Install
pip install healthkit
# With database drivers
pip install healthkit[postgres]
pip install healthkit[redis]
pip install healthkit[all]
Quick Start
One line to add production-grade health checks:
from fastapi import FastAPI
from healthkit import setup_health
app = FastAPI()
setup_health(
app,
postgres_url="postgresql://user:pass@localhost/mydb",
redis_url="redis://localhost:6379/0",
)
That's it. Your app now has /health and /health/ready endpoints.
Endpoints
| Endpoint | Purpose | Response |
|---|---|---|
GET /health |
Full health report | Overall status + details for each check |
GET /health/ready |
Readiness probe | Overall status only (for k8s) |
Both return 200 when healthy and 503 when any check fails.
Example Response
{
"status": "healthy",
"checks": [
{"name": "postgres", "status": "healthy", "latency_ms": 1.23},
{"name": "redis", "status": "healthy", "latency_ms": 0.45},
{"name": "disk", "status": "healthy", "usage_percent": 42.1, "free_gb": 58.32},
{"name": "memory", "status": "healthy", "usage_percent": 61.3, "available_gb": 6.12}
]
}
Advanced Usage
For more control, use the HealthCheck class directly:
from fastapi import FastAPI
from healthkit import HealthCheck, check_postgres, check_disk, check_memory
app = FastAPI()
health = HealthCheck()
health.add(check_postgres, url="postgresql://user:pass@localhost/mydb")
health.add(check_disk, threshold_percent=85)
health.add(check_memory, threshold_percent=80)
health.mount(app)
Custom Checks
Add your own check functions -- sync or async:
async def check_external_api() -> dict:
# your logic here
return {"name": "external-api", "status": "healthy", "latency_ms": 52.1}
health.add(check_external_api)
Available Checks
| Check | What it does | Extra dependency |
|---|---|---|
check_postgres |
Connects and runs SELECT 1 |
asyncpg |
check_redis |
Connects and sends PING |
redis |
check_disk |
Reports usage %, fails if above threshold | -- |
check_memory |
Reports usage %, fails if above threshold | -- |
Configuration
| Parameter | Default | Description |
|---|---|---|
postgres_url |
-- | PostgreSQL connection string |
redis_url |
-- | Redis connection string |
disk_threshold |
90 |
Disk usage % to trigger unhealthy |
memory_threshold |
90 |
Memory usage % to trigger unhealthy |
Kubernetes Integration
livenessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /health/ready
port: 8000
initialDelaySeconds: 3
periodSeconds: 5
License
MIT
Release files for healthkit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| healthkit-0.1.0.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| healthkit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.9 kB
Release files / healthkit-0.1.0.tar.gz
| Download URL | healthkit-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3568683847ef8c61739e6a1d4104cbbea7cdce619a1efb180fba0592fe3d569
|
|
BLAKE2b-256 checksum How to use checksums |
bc823727ebaec9b1e7e462a60b7858e73f3d3b7710dc3e4dbccd6f817148d51a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / healthkit-0.1.0-py3-none-any.whl
| Download URL | healthkit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0af619b4ea9366ad1849abe3e7edc336ea116f001426d0ebaa7a7c77a6e04a0f
|
|
BLAKE2b-256 checksum How to use checksums |
a406bbaff29dc4cfc5e2a410035e3cdc927df20542c590d33088d9663cd9aa06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|