Skip to content

maykinmedia/django-health-checks

Repository files navigation

Version:0.1.0
Source:https://github.com/maykinmedia/django-health-checks
Keywords:Django, Maykin, health checks
PythonVersion:3.12, 3.13

Build status Code quality checks Ruff Coverage status Documentation Status

python-versions django-versions pypi-version

Library to help with defining and running health checks for Maykin Django projects.

  • Python 3.12 or above
  • Django 4.2 or newer
pip install django-health-checks

Add 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_fn

To develop the library locally, use:

uv pip install -r pyproject.toml --all-extras

To 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 runserver

To 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

About

Library to help setup and run health checks in Maykin projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages