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
- Application version (read from
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_helsinki_health_endpoints-1.0.0.tar.gz.
File metadata
- Download URL: django_helsinki_health_endpoints-1.0.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eebf1baa6917d7b0e11123aec191df773883102ec1653025a86d7037dba389e2
|
|
| MD5 |
b12cfa4c064a03432f3a583e95fe1581
|
|
| BLAKE2b-256 |
d3fd16c24634b78720b725b9aed94a190287ea4a47207a99f618afd96d1e76c5
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_helsinki_health_endpoints-1.0.0.tar.gz -
Subject digest:
eebf1baa6917d7b0e11123aec191df773883102ec1653025a86d7037dba389e2 - Sigstore transparency entry: 1185747060
- Sigstore integration time:
-
Permalink:
City-of-Helsinki/django-helsinki-health-endpoints@ce25d1f6636b050e17af58c1165a40ba5c071ce0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/City-of-Helsinki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ce25d1f6636b050e17af58c1165a40ba5c071ce0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_helsinki_health_endpoints-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_helsinki_health_endpoints-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75670113e99bfd1fc23e317a3a22cff563140f495655c2a5f6ab219389dafd52
|
|
| MD5 |
87ca7e3a051cf110993bd6ec0d0c5624
|
|
| BLAKE2b-256 |
bc198dea4762b09f3fba5d973eee5afc7e721dfe18aa43dad5eb40323aaad9d3
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_helsinki_health_endpoints-1.0.0-py3-none-any.whl -
Subject digest:
75670113e99bfd1fc23e317a3a22cff563140f495655c2a5f6ab219389dafd52 - Sigstore transparency entry: 1185747066
- Sigstore integration time:
-
Permalink:
City-of-Helsinki/django-helsinki-health-endpoints@ce25d1f6636b050e17af58c1165a40ba5c071ce0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/City-of-Helsinki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ce25d1f6636b050e17af58c1165a40ba5c071ce0 -
Trigger Event:
push
-
Statement type: