Skip to main content

Shared backend services library for Django projects (Logging, Health, Cache, Rate Limiting, Security)

Project description

iil-django-commons

Shared backend services library for Django projects on the iil.pet platform.

Implements ADR-131 — Shared Backend Services for all Django Hub projects.

Installation

# Minimal (logging + health only)
pip install -e packages/iil-django-commons

# With cache support (django-redis)
pip install -e "packages/iil-django-commons[cache]"

# Full
pip install -e "packages/iil-django-commons[all]"

# From GitHub (pinned)
pip install "git+https://github.com/achimdehnert/platform.git@v0.1.0#subdirectory=packages/iil-django-commons"

Setup

# settings.py
INSTALLED_APPS = [
    "iil_commons",
    ...
]

MIDDLEWARE = [
    "iil_commons.logging.middleware.CorrelationIDMiddleware",
    "iil_commons.logging.middleware.RequestLogMiddleware",
    ...
]

IIL_COMMONS = {
    "LOG_FORMAT": "json",        # "json" | "human"
    "LOG_LEVEL": "INFO",
    "CACHE_DEFAULT_TTL": 300,
    "HEALTH_CHECKS": ["db", "redis"],
}
# urls.py
from django.urls import include, path

urlpatterns = [
    path("", include("iil_commons.health.urls")),
    ...
]

Modules (Phase 1)

Logging

# Auto-configured via AppConfig.ready() — no manual call needed.
# Override format per project:
IIL_COMMONS = {"LOG_FORMAT": "json"}  # structured JSON for production

Middlewares add X-Correlation-ID header to every request/response and log method, path, status, duration_ms, user_id per request.

Health Checks

Endpoint Purpose
/livez/ Liveness — always 200 if process is running
/healthz/ Readiness — checks DB, Redis, Celery (configurable)
/readyz/ Alias for /healthz/
IIL_COMMONS = {"HEALTH_CHECKS": ["db", "redis"]}

Cache

from iil_commons.cache import cached_view, cached_method, invalidate_pattern

@cached_view(ttl=300, key_func=lambda r: f"guests:{r.org.pk}")
def guest_list(request): ...

class GuestService:
    @cached_method(ttl=60, key_prefix="guest_service")
    def get_active(self, org_id): ...

# Invalidate on model save
invalidate_pattern(f"iil:view:guests:{org.pk}:*")

invalidate_pattern requires django-redis backend (iter_keys support).

Running Tests

cd packages/iil-django-commons
pip install -e ".[dev]"
pytest

Roadmap

Phase Modules Version
✅ Phase 1 Logging, Health, Cache v0.1.0
✅ Phase 2 Rate Limiting, Security Headers v0.2.0
✅ Phase 3 Email abstraction, Celery BaseTask, Prometheus v0.3.0
Phase 4 Consumer integration, own repo + CI, PyPI publish v0.4.0

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

iil_django_commons-0.3.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

iil_django_commons-0.3.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file iil_django_commons-0.3.0.tar.gz.

File metadata

  • Download URL: iil_django_commons-0.3.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for iil_django_commons-0.3.0.tar.gz
Algorithm Hash digest
SHA256 190ba89959283e01bbf8c697940e46a1142c29576fa6737137856860bdcee619
MD5 18add102dd58c09211c84d370cff92c6
BLAKE2b-256 8f105e73621fad2575b2e92eabb7b54157261ca6accebc888786207f34435288

See more details on using hashes here.

File details

Details for the file iil_django_commons-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for iil_django_commons-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f18eceb407a11c557534f79152e5996176c5eec79a27d4ff9f9d30447681ebf
MD5 e20b12c37ab297dd5597dd1c538f7aeb
BLAKE2b-256 6863f444276c09a17cce6150d1d35eb119d123e4d8239486882c95d5666eadb1

See more details on using hashes here.

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