summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--python-fastapi-health.spec316
-rw-r--r--sources1
3 files changed, 318 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..230c69b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/fastapi-health-0.4.0.tar.gz
diff --git a/python-fastapi-health.spec b/python-fastapi-health.spec
new file mode 100644
index 0000000..7345cd7
--- /dev/null
+++ b/python-fastapi-health.spec
@@ -0,0 +1,316 @@
+%global _empty_manifest_terminate_build 0
+Name: python-fastapi-health
+Version: 0.4.0
+Release: 1
+Summary: Heath check on FastAPI applications.
+License: MIT
+URL: https://github.com/Kludex/fastapi-health
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ce/97/27bdba7462672adf9815c0ac05c6d1c1ff49527b5d5a8a4e41034a58b6c2/fastapi-health-0.4.0.tar.gz
+BuildArch: noarch
+
+Requires: python3-fastapi
+
+%description
+<h1 align="center">
+ <strong>FastAPI Health 🚑️</strong>
+</h1>
+<p align="center">
+ <a href="https://github.com/Kludex/fastapi-health" target="_blank">
+ <img src="https://img.shields.io/github/last-commit/Kludex/fastapi-health" alt="Latest Commit">
+ </a>
+ <img src="https://img.shields.io/github/workflow/status/Kludex/fastapi-health/Test">
+ <img src="https://img.shields.io/codecov/c/github/Kludex/fastapi-health">
+ <br />
+ <a href="https://pypi.org/project/fastapi-health" target="_blank">
+ <img src="https://img.shields.io/pypi/v/fastapi-health" alt="Package version">
+ </a>
+ <img src="https://img.shields.io/pypi/pyversions/fastapi-health">
+ <img src="https://img.shields.io/github/license/Kludex/fastapi-health">
+</p>
+
+The goal of this package is to help you to implement the [Health Check API](https://microservices.io/patterns/observability/health-check-api.html) pattern.
+
+## Installation
+
+``` bash
+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:
+
+```python
+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 either `bool` or a `dict`.
+- `success_output`: An optional dictionary that will be the content response of a successful health call.
+- `failure_output`: An optional dictionary analogous to `success_output` for 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:
+
+``` Python
+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.
+
+
+%package -n python3-fastapi-health
+Summary: Heath check on FastAPI applications.
+Provides: python-fastapi-health
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-fastapi-health
+<h1 align="center">
+ <strong>FastAPI Health 🚑️</strong>
+</h1>
+<p align="center">
+ <a href="https://github.com/Kludex/fastapi-health" target="_blank">
+ <img src="https://img.shields.io/github/last-commit/Kludex/fastapi-health" alt="Latest Commit">
+ </a>
+ <img src="https://img.shields.io/github/workflow/status/Kludex/fastapi-health/Test">
+ <img src="https://img.shields.io/codecov/c/github/Kludex/fastapi-health">
+ <br />
+ <a href="https://pypi.org/project/fastapi-health" target="_blank">
+ <img src="https://img.shields.io/pypi/v/fastapi-health" alt="Package version">
+ </a>
+ <img src="https://img.shields.io/pypi/pyversions/fastapi-health">
+ <img src="https://img.shields.io/github/license/Kludex/fastapi-health">
+</p>
+
+The goal of this package is to help you to implement the [Health Check API](https://microservices.io/patterns/observability/health-check-api.html) pattern.
+
+## Installation
+
+``` bash
+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:
+
+```python
+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 either `bool` or a `dict`.
+- `success_output`: An optional dictionary that will be the content response of a successful health call.
+- `failure_output`: An optional dictionary analogous to `success_output` for 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:
+
+``` Python
+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.
+
+
+%package help
+Summary: Development documents and examples for fastapi-health
+Provides: python3-fastapi-health-doc
+%description help
+<h1 align="center">
+ <strong>FastAPI Health 🚑️</strong>
+</h1>
+<p align="center">
+ <a href="https://github.com/Kludex/fastapi-health" target="_blank">
+ <img src="https://img.shields.io/github/last-commit/Kludex/fastapi-health" alt="Latest Commit">
+ </a>
+ <img src="https://img.shields.io/github/workflow/status/Kludex/fastapi-health/Test">
+ <img src="https://img.shields.io/codecov/c/github/Kludex/fastapi-health">
+ <br />
+ <a href="https://pypi.org/project/fastapi-health" target="_blank">
+ <img src="https://img.shields.io/pypi/v/fastapi-health" alt="Package version">
+ </a>
+ <img src="https://img.shields.io/pypi/pyversions/fastapi-health">
+ <img src="https://img.shields.io/github/license/Kludex/fastapi-health">
+</p>
+
+The goal of this package is to help you to implement the [Health Check API](https://microservices.io/patterns/observability/health-check-api.html) pattern.
+
+## Installation
+
+``` bash
+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:
+
+```python
+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 either `bool` or a `dict`.
+- `success_output`: An optional dictionary that will be the content response of a successful health call.
+- `failure_output`: An optional dictionary analogous to `success_output` for 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:
+
+``` Python
+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.
+
+
+%prep
+%autosetup -n fastapi-health-0.4.0
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-fastapi-health -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Wed Apr 12 2023 Python_Bot <Python_Bot@openeuler.org> - 0.4.0-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..94d0090
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+8bfd9414cd27b17e03b8f520c84c2c2b fastapi-health-0.4.0.tar.gz