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

platform_context-0.5.0.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.

platform_context-0.5.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file platform_context-0.5.0.tar.gz.

File metadata

  • Download URL: platform_context-0.5.0.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 platform_context-0.5.0.tar.gz
Algorithm Hash digest
SHA256 6a399eb44281b070450a3a438baea16cb727810ae55b178c14fa6a40f2acaced
MD5 41b08811a3262bd879b2963340a0e477
BLAKE2b-256 37c4d3c697586176db5d2c1d977e6aa973e798a3a05eb7597ade52a0c99b89c1

See more details on using hashes here.

File details

Details for the file platform_context-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for platform_context-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 680bcdfdf37a63c3e4600a9b6f903d3835271a2fbbeea0b329e6729f08403bfa
MD5 05ae698c35d6eabc594fbbb334e8561a
BLAKE2b-256 46b08a575e521eccf62fc858cf11ede7279531fe5c5be1280c6d5562930dba2f

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