Skip to main content

Shared platform foundation for all Django projects (Context, Tenancy, Audit, Outbox)

Project description

platform-context

Shared platform foundation for all Django projects in the iil.pet ecosystem.

What it provides

  • Request Context — Thread-safe context propagation (tenant_id, user_id, request_id)
  • Multi-Tenancy Middleware — Subdomain-based tenant resolution + Postgres RLS
  • Audit Event Logging — Structured audit trail (model-agnostic)
  • Outbox Pattern — Reliable event publishing within transactions
  • Exception Hierarchy — Structured platform exceptions
  • Template Context Processors — Tenant/permission info in Django templates

Installation

pip install -e packages/platform-context

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "platform_context",
]

Usage

from platform_context import get_context, set_tenant, set_user_id
from platform_context.middleware import SubdomainTenantMiddleware
from platform_context.audit import emit_audit_event
from platform_context.exceptions import TenantNotFoundError

Configuration

Setting Default Description
TENANT_BASE_DOMAIN "localhost" Base domain for subdomain resolution
TENANT_MODEL "tenancy.Organization" Dotted path to tenant model
TENANT_SLUG_FIELD "slug" Field name for slug lookup
TENANT_ID_FIELD "tenant_id" Field name for tenant_id
TENANT_ALLOW_LOCALHOST False Allow admin access without tenant (dev)
PLATFORM_AUDIT_MODEL None Dotted path to AuditEvent model
PLATFORM_OUTBOX_MODEL None Dotted path to OutboxMessage model

Relation to bfagent-core

platform-context is the framework-agnostic foundation extracted from bfagent-core (see ADR-028). bfagent-core now depends on platform-context and re-exports its public API for backward compatibility.

New projects should depend on platform-context directly.

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_platform_context-0.5.1.tar.gz (25.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_platform_context-0.5.1-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file iil_platform_context-0.5.1.tar.gz.

File metadata

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

File hashes

Hashes for iil_platform_context-0.5.1.tar.gz
Algorithm Hash digest
SHA256 a6e8ed263267dc1d1be4ec0800e1c4b87b3c5bb83d96b553c2dc996670dd04ae
MD5 957dc6be717e5825e1ef6b6756834251
BLAKE2b-256 c063c969aa6d7f357895a32b85dac00d5825ae09e5dd01023c457f78ffa09bae

See more details on using hashes here.

File details

Details for the file iil_platform_context-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for iil_platform_context-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b9e35d1f0ff26145addb3f8d335ddff5eb99fdc8dbcd2704b5255d3e62c90b2
MD5 f92bcceea1eac335884a2eb5a3c6e308
BLAKE2b-256 820bde7c972366d545976bf0d577694ea40970e784964d2664e5e7df32ce6a44

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