Skip to main content

Health check utilities for FastAPI applications.

Project description

fastapi-health-check logo

fastapi-health-check

FastAPI health checks with a small public API, a visual status page, and JSON responses from the same endpoint.

Example interface

fastapi-health-check example interface

What the library provides

  • A base contract for advanced checks
  • A lightweight registry for collecting and running checks
  • A single /ht endpoint with HTML by default
  • JSON responses when the client sends Accept: application/json
  • A simple way to monitor any custom area of your system

Important note

The library does not ship with a database check by default.

The only built-in check today is AppAliveCheck, which reports that the application is up. Database, Redis, queues, external APIs, or any other monitored area are meant to be registered by the user.

Quick start

from fastapi import FastAPI

from fastapi_health_check import AppAliveCheck, HealthRegistry, health_check, install_health_check


app = FastAPI()
registry = HealthRegistry(
    [
        AppAliveCheck(),
        health_check("database", lambda: "connection ok"),
        health_check("redis", lambda: "cache reachable"),
    ]
)

install_health_check(app, registry)

This exposes GET /ht.

  • In a browser, the route renders an HTML health page
  • For automated integrations, the same route returns JSON when the client sends Accept: application/json

Monitoring custom areas

If you want to monitor anything beyond the built-in app liveness check, the easiest option is the health_check() factory.

You can use it for:

  • databases
  • Redis or cache layers
  • background queues
  • external APIs
  • storage services
  • internal domain-specific dependencies

Synchronous checks

from fastapi_health_check import health_check

database_check = health_check("database", lambda: "connection ok")
redis_check = health_check("redis", lambda: "cache reachable")

Asynchronous checks

from fastapi_health_check import health_check


async def payments_api_check() -> str | None:
    return "payments API available"


payments_check = health_check("payments_api", payments_api_check)

Class-based checks for advanced cases

from fastapi_health_check import HealthCheck


class QueueCheck(HealthCheck):
    default_name = "queue"

    async def check(self) -> str | None:
        return "queue connected"

Use class-based checks when you want:

  • dependency injection through __init__
  • reusable state
  • more structured custom behavior

Local manual testing

The repository includes a local example application at src/examples/basic_app.py.

Run it with:

uv run uvicorn src.examples.basic_app:app --reload

Then open:

  • http://127.0.0.1:8000/ht for the HTML page
  • curl -H "Accept: application/json" http://127.0.0.1:8000/ht for JSON

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

fastapi_ht-0.1.0.tar.gz (855.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_ht-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_ht-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_ht-0.1.0.tar.gz
  • Upload date:
  • Size: 855.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapi_ht-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1c7c81255c12e6588eb7303f8d3ae2df4f3d3dbb0f101381b7d890eee6216964
MD5 8722429ca40fbd26eb205af9797fd3f8
BLAKE2b-256 5d2503ed27a0cffcae5b06f2b3921c537e117db0c2832552413849036ba2b468

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_ht-0.1.0.tar.gz:

Publisher: publish.yml on PinnLabs/fastapi-health-check

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_ht-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_ht-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapi_ht-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb47697b855cadb496fdaf95928bf0a54521a2a846cda7bc838e7b1496d7bd01
MD5 c493b37360ab8c92ca01e18921a6b6dd
BLAKE2b-256 66124518d3fa2cdbd66743ba2db779c6ecaed9d213d243ef6efc6467e7621c5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_ht-0.1.0-py3-none-any.whl:

Publisher: publish.yml on PinnLabs/fastapi-health-check

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page