fastapi-watch — structured health & readiness checks for FastAPI #15265
rgreen1207
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
|
Interesting! Not sure about |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
I built fastapi-watch because FastAPI doesn't ship with any real observability out of the box. If you want to know what's actually happening inside your app — whether your database is healthy, how your queues are behaving, what your error rates look like — you're either writing it yourself or paying for something like NewRelic or Datadog. I wanted something in-depth that gave me the full picture without the cost or complexity. The goal was to keep it as lightweight, simple to set up, and non-interfering as possible.
The typical
/healthendpoint that just returns{"status": "ok"}telling you absolutely nothing. Writing per-app health logic from scratch means handling concurrency, caching, circuit breaking, Prometheus metrics, and SSE streaming yourself — every time.What it does
Add
/health/live,/health/ready,/health/status,/health/history,/health/metrics, and/health/dashboardto any FastAPI app with a single registry call:All probes run concurrently, so if, for example, Redis takes 5 seconds to respond, your Postgres check still comes back in 2ms and your
/health/readyendpoint doesn't stall waiting for it. Each probe lives in its own async task and reports independently.A few things I think are worth highlighting
Passive observers instead of synthetic pings. Many of the built-in probes (PostgreSQL, Redis, MongoDB, HTTP, SMTP) use a
@probe.watchdecorator to instrument your existing functions rather than making their own test requests on a timer. This means no extra load on your dependencies and no burned API credits on third-party services.Three-state health. Probes can return
healthy,degraded, orunhealthy. Degraded means "still serving traffic but investigate soon" —/health/readystays 200, the dashboard shows amber, and Prometheus surfaces aprobe_degradedgauge.ProbeGroup mirrors FastAPI's
APIRouterpattern so you can declare probes in the modules that own them and include them at startup — same pattern you already use for routes.Live dashboard at
/health/dashboard— self-contained HTML, no extra dependencies, updates in real time over SSE.Kubernetes
Maps directly onto Kubernetes probe types:
Built-in probes
PostgreSQL, MySQL, SQLAlchemy, Redis, Memcached, RabbitMQ, Kafka, MongoDB, Celery, HTTP, SMTP, TCP/DNS, EventLoop lag, and more — each returning service-specific metadata in the
detailsfield alongside the pass/fail result.Alerting
You can hook into state changes to fire alerts whenever a probe flips between healthy, degraded, and unhealthy. There are built-in alerters for Slack, Microsoft Teams, and PagerDuty, or you can pass any HTTP endpoint as a generic webhook. Custom alerters are also supported if you need something more specific — just subclass
BaseAlerterand implement a singlenotifymethod.Alerts are fire-and-forget and never block health check execution. They're also automatically suppressed during maintenance mode, so you don't get paged for planned downtime.
Links
pip install fastapi-watchWould love feedback — especially from anyone running FastAPI in Kubernetes or behind a load balancer. Happy to answer questions or take feature requests.
Beta Was this translation helpful? Give feedback.
All reactions