FastAPI Health 🚑️
The goal of this package is to help you to implement the Health Check API pattern.
Installation
pip install fastapi-health
Quick Start
Create the health check endpoint dynamically using different conditions. Each condition is a callable, and you can even have dependencies inside of it:
from fastapi import FastAPI, Depends
from fastapi_health import health
def get_session():
return True
def is_database_online(session: bool = Depends(get_session)):
return session
app = FastAPI()
app.add_api_route("/health", health([is_database_online]))
Advanced Usage
The health() method receives the following parameters:
conditions: A list of callables that represents the conditions of your API, it can return eitherboolor adict.success_output: An optional dictionary that will be the content response of a successful health call.failure_output: An optional dictionary analogous tosuccess_outputfor failure scenarios.success_status: An integer that overwrites the default status (200) in case of success.failure_status: An integer that overwrites the default status (503) in case of failure.
It's important to notice that you can have a peculiar behavior in case of hybrid return statements (bool and dict) on the conditions.
For example:
from fastapi import FastAPI
from fastapi_health import health
def healthy_condition():
return {"database": "online"}
def sick_condition():
return False
app = FastAPI()
app.add_api_route("/health", health([healthy_condition, sick_condition]))
This will generate a response composed by the status being 503 (default failure_status), because sick_condition returns False, and the JSON body {"database": "online"}. It's not wrong, or a bug. It's meant to be like this.
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for fastapi-health 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi-health-0.4.0.tar.gz | 4.0 kB | Without provenance | Details for fastapi-health-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_health-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_health-0.4.0-py3-none-any.whl |
Total release size: 8.0 kB
Release files / fastapi-health-0.4.0.tar.gz
| Download URL | fastapi-health-0.4.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0781b2359732d50cddda1195784f78950265c6b3689d7a1e6e65a21aed4d6a5
|
|
BLAKE2b-256 checksum How to use checksums |
ce9727bdba7462672adf9815c0ac05c6d1c1ff49527b5d5a8a4e41034a58b6c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.8 CPython/3.8.11 Linux/5.11.0-27-generic
|
Release files / fastapi_health-0.4.0-py3-none-any.whl
| Download URL | fastapi_health-0.4.0-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6c1795f7596009cffa7a84d5a67a6b66bbf9d6ce79b040fd50601ed5392089f
|
|
BLAKE2b-256 checksum How to use checksums |
cf3dbc1003fb1708f7cfe1546a22875c38ebc901e621564aeef3bb97f32b1ab2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.8 CPython/3.8.11 Linux/5.11.0-27-generic
|
Security for fastapi-health 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.