Skip to main content

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 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",
  "version": "1.2.3",
  "release": "theapp@1.2.3",
  "database": "ok"
}

If the database check fails:

HTTP 503

{
  "status": "error",
  "version": "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.

Metadata

Release files for django-helsinki-health-endpoints 2.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-helsinki-health-endpoints 2.0.0
File Size Uploaded Provenance Actions
django_helsinki_health_endpoints-2.0.0.tar.gz 10.8 kB With provenance Details for django_helsinki_health_endpoints-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-helsinki-health-endpoints 2.0.0
File Interpreter ABI Platform Actions
django_helsinki_health_endpoints-2.0.0-py3-none-any.whl Python 3 none any Details for django_helsinki_health_endpoints-2.0.0-py3-none-any.whl

Total release size: 18.0 kB

Release files / django_helsinki_health_endpoints-2.0.0.tar.gz

Download URL django_helsinki_health_endpoints-2.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
061176e3ed5bbb11af41cb1ceaa0bcf967641d98c325520760db2f6f9a1e42bc
BLAKE2b-256 checksum
How to use checksums
7b7b6a8b3b77f440c7dfd39c04282e0cbc938347cad238ea95860c00dedd3b2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / django_helsinki_health_endpoints-2.0.0-py3-none-any.whl

Download URL django_helsinki_health_endpoints-2.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27cd9192cfd67e7f0aabf9a0e75ea969364da529e031557647bc25134cdbf376
BLAKE2b-256 checksum
How to use checksums
43d0f46a52da93387ab458106f8b7b78363c86e6c5801a4d94ec3650f32f519e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Security for django-helsinki-health-endpoints 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_helsinki_health_endpoints-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files Full provenance

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