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
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 iil_platform_context-0.7.0.tar.gz.
File metadata
- Download URL: iil_platform_context-0.7.0.tar.gz
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c75edc166a152ae17b274b042e4ac6119d229d75a44de7eb366a75879e42ca9
|
|
| MD5 |
6f160a76b683290402f4486e5ba00b4a
|
|
| BLAKE2b-256 |
038f996b4d1f977cf96c49d799f1a0b7d21d35c620ed5726b766c32347601ef6
|
File details
Details for the file iil_platform_context-0.7.0-py3-none-any.whl.
File metadata
- Download URL: iil_platform_context-0.7.0-py3-none-any.whl
- Upload date:
- Size: 40.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d16de129a2353bf9ae9a027db861ad43afb815928bd7f96fa91b933c8242b34a
|
|
| MD5 |
f041368d2a8ebb64e6ee9ac07279ac68
|
|
| BLAKE2b-256 |
961c54f88a15b4c94b523238afa5819198ee0d6e58874cac5c805a047f1b4557
|