Skip to main content

django-alive 🕺

tests coverage PyPI Python Versions

Provides two healthcheck endpoints for your Django application:

Alive

Verifies the WSGI server is responding.

  • Default URL: /-/alive/
  • Success:
    • status code: 200
    • content: ok
  • Failure: This view never returns a failure. A failure would mean your WSGI server is not running.

Health

Verifies services are ready.

  • Default URL: /-/health/
  • Success:
    • status_code: 200
    • content: {"healthy": true}
  • Failure:
    • status_code: 503
    • content: {"healthy": false, "errors": ["error 1", "error 2"]}

By default the health endpoint will test the database connection, but can be configured to check the cache, staticfiles, or any additional custom checks.

Supports Django 1.10+ on both Python 2 & 3.

Install

pip install django-alive

Configure

Add this to your project's urlpatterns:

path("-/", include("django_alive.urls"))

For versions before Django 2.0, use:

url(r"-/", include("django_alive.urls"))

Enabling Checks

The default "health" endpoint will test a simple SELECT 1 query on the database. Additional checks can be enabled in your Django settings.

Use the ALIVE_CHECKS setting to configure the checks to include. It is a dictionary with the path to a Python function as a key and any keyword arguments to pass to that function as a value. A full example:

ALIVE_CHECKS = {
    "django_alive.checks.check_database": {},
    "django_alive.checks.check_staticfiles": {
        "filename": "img/favicon.ico",
    },
    "django_alive.checks.check_cache": {
        "cache": "session",
        "key": "test123",
    },
}

Custom Checks

django-alive is designed to easily extend with your own custom checks. Simply define a function which performs your check and raises a django_alive.HealthcheckFailure exception in the event of a failure. See checks.py for some examples on how to write a check.

Bypassing the ALLOWED_HOSTS Check

Often, load balancers will not pass a Host header when probing a healthcheck endpoint. This presents a problem for Django's host header validation. A middleware is included that will turn off the host checking only for the healthcheck endpoints. This is safe since these views never do anything with the Host header.

Enable the middleware by inserting this at the beginning of your MIDDLEWARES:

MIDDLEWARES = [
    "django_alive.middleware.healthcheck_bypass_host_check",
    # ...
]

1.0.0 (2018-08-21)

  • Initial release

Metadata

Release files for django-alive 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-alive 1.0.0
File Size Uploaded
django-alive-1.0.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-alive 1.0.0
File Interpreter ABI Platform
django_alive-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.5 kB

Release files / django-alive-1.0.0.tar.gz

Download URL django-alive-1.0.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
72d9e12e62add240b440bc366b1b7eb871d8a3637817de8e7bbdc27db9751992
BLAKE2b-256 checksum
How to use checksums
62258fba65bedd2600141b9dcec94fc53e81425f5b787d03ce11474e35f5f584
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

Release files / django_alive-1.0.0-py2.py3-none-any.whl

Download URL django_alive-1.0.0-py2.py3-none-any.whl
Size 7.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3f281b7e9ff93598ce9b1af46012a34372845a9e0c6c3cb49981cadf06a09d18
BLAKE2b-256 checksum
How to use checksums
5ab0a82b06b005ea2322df79baf13fcc73ff4027fecfc2a67b08683a04b91bae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

Release history Release notifications | RSS feed

2.0.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

1 release file

1.1.0

2 release files

1.0.1

2 release files

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page