| Version: | 0.1.0 |
|---|---|
| Source: | https://github.com/maykinmedia/django-health-checks |
| Keywords: | Django, Maykin, health checks |
| PythonVersion: | 3.12, 3.13 |
Library to help with defining and running health checks for Maykin Django projects.
Contents
- Python 3.12 or above
- Django 4.2 or newer
pip install django-health-checksAdd maykin_health_checks to the Django INSTALLED_APPS:
INSTALLED_APPS = [
...
"maykin_health_checks",
...
]To have an API view that returns the results of the performed health checks,
add the following to the urlpatterns:
from django.urls import path
from maykin_health_checks.api.views import HealthChecksView
urlpatterns = [
...
path(
"health-checks",
HealthChecksView.as_view(
checks_collector=my_checks_collector_fn
),
name="health-checks",
),
]Where my_checks_collector_fn is a Callable[[], Iterable[HealthCheck]]. It is used to retrieve which health checks should
be performed by the view. You can also add the view multiple times to the urlpatters with different checks_collector arguments
if you want to have multiple health check views that run different checks.
There is also a management command that can be used to run health checks from the CLI.
django-admin health_checks --checks-collector dotted.path.to.my_checks_collector_fnTo develop the library locally, use:
uv pip install -r pyproject.toml --all-extrasTo run the test app, in the root of the repository run:
export DJANGO_SETTINGS_MODULE=testapp.settings
export PYTHONPATH=$PYTHONPATH:`pwd`Then, you can run:
django-admin runserverTo run the tests without tox, you can do the following (from the root of the repository):
export DJANGO_SETTINGS_MODULE=testapp.settings
export PYTHONPATH=$PYTHONPATH:`pwd`
pytest tests