Skip to main content

Reusable Django app providing unified healthz and readiness endpoints for City of Helsinki projects

Project description

django-helsinki-health-endpoints

Reusable Django app providing unified /healthz and /readiness endpoints for City of Helsinki projects.

Features

  • /healthz — Kubernetes liveness probe (always returns HTTP 200)
  • /readiness — Kubernetes readiness probe with:
    • Application version (read from pyproject.toml)
    • Database connectivity check
    • Sentry release tag

Installation

pip install django-helsinki-health-endpoints

Configuration

1. Add to INSTALLED_APPS

INSTALLED_APPS = [
    # ...
    "helsinki_health_endpoints",
]

2. Include URL patterns

from django.urls import include, path

urlpatterns = [
    path("", include("helsinki_health_endpoints.urls")),
    # ...
]

This registers healthz and readiness endpoints at the root. You can mount them under a prefix if needed:

urlpatterns = [
    path("__", include("helsinki_health_endpoints.urls")),  # => /__healthz, /__readiness
]

You can also register the endpoints individually instead of using include:

from helsinki_health_endpoints.views import healthz, readiness

urlpatterns = [
    path("healthz", healthz),
    path("readiness", readiness),
]

3. Settings

helsinki_health_endpoints reads the following keys from django.conf.settings:

Setting Required Description
BASE_DIR Yes Project root directory, used to locate pyproject.toml for the version
SENTRY_RELEASE No Release tag/version string exposed in the /readiness response (default: "")

BASE_DIR is typically already defined in your project's settings.py:

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

To expose your Sentry release in the /readiness response, add:

import os

SENTRY_RELEASE = os.environ.get("SENTRY_RELEASE", "")

System checks

helsinki_health_endpoints registers Django system checks that run automatically on startup (or via manage.py check).

ID Level Description
helsinki_health_endpoints.E001 Error BASE_DIR is not defined in settings.
helsinki_health_endpoints.E002 Error pyproject.toml is excluded by .dockerignore (the file is required at runtime to read the package version).
helsinki_health_endpoints.W001 Warning .dockerignore exists but could not be read (e.g. permission error).

Response examples

GET /healthz

HTTP 200

GET /readiness

{
  "status": "ok",
  "packageVersion": "1.2.3",
  "release": "theapp@1.2.3",
  "database": "ok"
}

If the database check fails:

HTTP 503

{
  "status": "error",
  "packageVersion": "1.2.3",
  "release": "theapp@1.2.3",
  "database": "error"
}

Development

This project uses Hatch for development, testing, and building.

Install Hatch

pip install hatch

Set up the development environment

Hatch manages virtual environments automatically. To create and enter a shell in the default environment:

hatch shell

To install pre-commit hooks (required before committing):

hatch run lint

This will install pre-commit and run all hooks. Alternatively:

pre-commit install

Running tests

Run the full test matrix (all Python × Django version combinations defined in pyproject.toml):

hatch test -a

Run tests for a specific Python version only:

hatch test -i py=3.12

Run tests for a specific Python + Django combination:

hatch test -i py=3.12 -i django=5.2

Pass arguments through to pytest (e.g. run a single test file):

hatch test -- tests/test_views.py -v

The test matrix

The matrix defined in pyproject.toml is:

Python Django
3.10, 3.11 5.2
3.12, 3.13, 3.14 5.2, 6.0

Each combination gets its own isolated venv (created automatically by hatch on first run, stored in hatch's environment cache).

Manual testing

The repository includes a manage.py pre-configured with the test settings (SQLite in-memory database). You can run it from within the default Hatch environment:

hatch run python manage.py runserver

Or enter the environment shell first and run it directly:

hatch shell
python manage.py runserver

Then hit the endpoints:

curl http://localhost:8000/healthz
curl http://localhost:8000/readiness

Linting

# Run all pre-commit hooks against all files
hatch run lint

# Or run pre-commit directly (after installing hooks)
pre-commit run --all-files

# Run only ruff lint (with autofix)
pre-commit run ruff-check --all-files

# Run only ruff formatter
pre-commit run ruff-format --all-files

License

This project is licensed under the MIT License — see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_helsinki_health_endpoints-1.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file django_helsinki_health_endpoints-1.0.0.tar.gz.

File metadata

File hashes

Hashes for django_helsinki_health_endpoints-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eebf1baa6917d7b0e11123aec191df773883102ec1653025a86d7037dba389e2
MD5 b12cfa4c064a03432f3a583e95fe1581
BLAKE2b-256 d3fd16c24634b78720b725b9aed94a190287ea4a47207a99f618afd96d1e76c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_helsinki_health_endpoints-1.0.0.tar.gz:

Publisher: publish.yml on City-of-Helsinki/django-helsinki-health-endpoints

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_helsinki_health_endpoints-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_helsinki_health_endpoints-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75670113e99bfd1fc23e317a3a22cff563140f495655c2a5f6ab219389dafd52
MD5 87ca7e3a051cf110993bd6ec0d0c5624
BLAKE2b-256 bc198dea4762b09f3fba5d973eee5afc7e721dfe18aa43dad5eb40323aaad9d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_helsinki_health_endpoints-1.0.0-py3-none-any.whl:

Publisher: publish.yml on City-of-Helsinki/django-helsinki-health-endpoints

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page