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

Installation

Install with uv:

uv add fastapi-ht

Install with pip:

pip install fastapi-ht

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.1.tar.gz (885.7 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.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_ht-0.1.1.tar.gz
  • Upload date:
  • Size: 885.7 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.1.tar.gz
Algorithm Hash digest
SHA256 4a79d07a3faaa5c15c429eedfc8321a0fdbb303e4d379adedc008992e3d49f0b
MD5 044bc72a6e514454c8e1d81f2e50fffd
BLAKE2b-256 8cd9dcc8a74fb959c5f4917023492760906a3c66ab6fa69b751fd556a8b614a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_ht-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_ht-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ae6ebebc92944bd585718f3987e688eccb91a0dceccf44119e018e9183e81a7
MD5 966da61ecb4f84268634aed619b42157
BLAKE2b-256 792319eb5336ce6b98320c188070b434f81dec9e7ea89c241cb0535a35954d7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_ht-0.1.1-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