Health checks

async alchemiq.check_health(*, timeout=5.0)[source]

Run health probes for all configured backends concurrently.

Returns a HealthReport aggregating all component results. Probes are skipped for backends that are not configured. HealthReport.healthy is True only if every component probe succeeds. Each probe is guarded by timeout seconds; a probe that times out or errors is recorded as unhealthy.

E.g.:

from alchemiq.health import check_health

report = await check_health()
if not report.healthy:
    print(report.to_dict())

# FastAPI integration:
from alchemiq.fastapi import health_router
app.include_router(health_router())
Parameters:

timeout (float) – per-probe timeout in seconds (default 5.0).

Returns:

a HealthReport aggregating all component results.

Return type:

HealthReport

Note

When no backends are configured, returns a trivially healthy report with an empty components tuple - useful in unit tests that haven’t called configure.

See also

HealthReport - the returned aggregate report.

class alchemiq.HealthReport(healthy, components)[source]

Bases: object

Aggregate health report across all probed components.

Returned by check_health(). healthy is True only when every ComponentHealth in components is healthy.

E.g.:

report = await check_health()
data = report.to_dict()
# {"status": "healthy", "checks": [{"name": "postgres", "healthy": True, ...}]}

See also

check_health() - produces this report.

Parameters:
to_dict()[source]

Serialise to a JSON-safe dict with status and checks keys.

Return type:

dict[str, object]

class alchemiq.ComponentHealth(name, healthy, latency_ms, error=None)[source]

Bases: object

Probe result for a single backend component.

Returned as part of HealthReport from check_health(). latency_ms is None when the probe did not complete (error or timeout).

Parameters: