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.2.0.tar.gz (903.5 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.2.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_ht-0.2.0.tar.gz
  • Upload date:
  • Size: 903.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 dbfa1d9982a0cc72fa8edee62464ca47cb48c2e4cc8d27e9ce44061af5498043
MD5 634c3c304ba17b36a8af348103478a2c
BLAKE2b-256 684e6b26ee2961fd9f82214a1368d879edcc06ae3e609805fc7ed914637e0117

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: fastapi_ht-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e4b91521cca9fc5bc72914bef1c8e4b630dea012ed15846ae0c123a8cca6d7a
MD5 e455982a7270954961bdde9245e40ec2
BLAKE2b-256 7e571ca310a1655277f11faf43b64f38aa526a13b584f538d1430a74bd6ea70e

See more details on using hashes here.

Provenance

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