FastAPI Healthchecks
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install fastapi-healthchecksFastAPI health checks
Configurable health checks endpoints for FastAPI applications.
Quickstart
app = FastAPI()
app.include_router(
HealthcheckRouter(
Probe(
name="readiness",
checks=[
PostgreSqlCheck(host="db.example.com", username=..., password=...),
RedisCheck(host="redis.example.com", username=..., password=...),
],
),
Probe(
name="liveness",
checks=[
...,
],
),
),
prefix="/health",
)
The probes from this example will be available as GET /health/readiness and GET /health/liveness.
Bundled checks
PostgreSqlCheck– checks PostgreSQL server availabilityRedisCheck– checks Redis server availabilityRabbitMqCheck– checks RabbitMQ server availabilitySettingsCheck– validates settings models based on pydantic BaseModelHttpCheck– checks availability of specified URLCephCheck– checks Ceph server availability
Custom checks
You can create your own checks by providing custom fastapi_healthchecks.checks.Check implementations. Like this:
class MaintenanceCheck(Check):
async def __call__(self) -> CheckResult:
if is_maintenance():
return CheckResult(name="Maintenance", passed=False, details="Closed for maintenance")
else:
return CheckResult(name="Maintenance", passed=True)