| Version: | 0.1.0 |
|---|---|
| Source: | https://github.com/maykinmedia/config-checks |
| Keywords: | Django, Maykin, health checks |
| PythonVersion: | 3.12, 3.13 |
This library aims to standardise how health checks for Maykin Django applications
are run. The checks are meant to validate that the configuration that is normally
performed in the Admin or via django-setup-configuration is correct.
Contents
- Python 3.12 or above
- Django 4.2 or newer
pip install maykin-config-checksAdd maykin_config_checks to the Django INSTALLED_APPS:
INSTALLED_APPS = [
...
"maykin_config_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_config_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 config_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