Skip to main content

fastapi_healthcheck

Easy to use health check for your FastAPI. This is the root module that will let you add implement and expand your usage of health checks, with FastAPI.

This module does not contain any service checkers, but you can easily add them. The other modules are not in this root module due to different dependencies required for each one. This is made so you only bring in the packages that you need to not add extra packages.

Install

pip install fastapi-healthcheck or poetry add fastapi-healthcheck

Adding Health Checks

Here is what you need to get started.

from fastapi import FastAPI
from fastapi_healthcheck import HealthCheckFactory, healthCheckRoute
from fastapi_healthcheck_sqlalchemy import HealthCheckSQLAlchemy

app = FastAPI()

# Add Health Checks
_healthChecks = HealthCheckFactory()

# SQLAlchemy comes from fastapi-healthcheck-sqlalchemy
_healthChecks.add(HealthCheckSQLAlchemy(alias='postgres db', connectionUri=cs.value, table=SmtpContactsSqlModel, tags=('postgres', 'db', 'sql01')))

# This will check external URI and validate the response that is returned.
# fastapi-healthcheck-uri
_healthChecks.add(HealthCheckUri(alias='reddit', connectionUri="https://www.reddit.com/r/aww.json", tags=('external', 'reddit', 'aww')))
app.add_api_route('/health', endpoint=healthCheckRoute(factory=_healthChecks))

Returned Data

When you request your health check, it will go and check all the entries that have been submitted and run a basic query against them. If they come back as expected, then a status code is 200. But if it runs into an error, it will return a 500 error.

{
    "status":"Healthy",
    "totalTimeTaken":"0:00:00.671642",
    "entities":[
        {
            "alias":"postgres db",
            "status":"Healthy",
            "timeTaken":"0:00:00.009619",
            "tags":["postgres","db","sql01"]
        },
        {
            "alias":"reddit",
            "status":"Unhealthy",
            "timeTaken":"0:00:00.661716",
            "tags":["external","reddit","aww"]
        }
    ]
}

Available Modules

If you have made a public service module and want to see it on this list, please open a new issue so we can add it to the list.

Writing a custom module

You can easily expand on this core module to add other health checks for other services. Generate a new service that pulls in HealthCheckInterface and HealthCheckBase. With those, you can build the respective class around the interface.

Once you have your service ready to go, add it to the HealthCheckFactory, and let the testing start.

If you would like to see an example of a custom service see fastapi_healthcheck_sqlalchemy. This will give you a better example of what you need to do to create your own module to interface with healthcheck.

Release files for fastapi_healthcheck 0.2.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi_healthcheck 0.2.13
File Size Uploaded
fastapi_healthcheck-0.2.13.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi_healthcheck 0.2.13
File Interpreter ABI Platform
fastapi_healthcheck-0.2.13-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / fastapi_healthcheck-0.2.13.tar.gz

Download URL fastapi_healthcheck-0.2.13.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
139080f2b4ad5d3400054b12e53afb43e97db34bc1d4676db956db2302f0bdde
BLAKE2b-256 checksum
How to use checksums
1d9bab3448739829a5e1f6b1a71f35969f7182d9068ff36b345d413769df26a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1022-azure

Release files / fastapi_healthcheck-0.2.13-py3-none-any.whl

Download URL fastapi_healthcheck-0.2.13-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a58760d346a1be7990a6a3f1de9cf8eac07e8cff94b29a0de7d6da944e5bab64
BLAKE2b-256 checksum
How to use checksums
4c14eff8b7a35db9d798b9565543d65a7d5f231a2776d9d53a5155ab5b2ce9f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1022-azure

Release history Release notifications | RSS feed

This release

0.2.13 This release

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page