Skip to main content

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.

Metadata

Release files for platform-context 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for platform-context 0.5.0
File Size Uploaded Provenance
platform_context-0.5.0.tar.gz 25.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for platform-context 0.5.0
File Interpreter ABI Platform
platform_context-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 52.6 kB

Release files / platform_context-0.5.0.tar.gz

Download URL platform_context-0.5.0.tar.gz
Size 25.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6a399eb44281b070450a3a438baea16cb727810ae55b178c14fa6a40f2acaced
BLAKE2b-256 checksum
How to use checksums
37c4d3c697586176db5d2c1d977e6aa973e798a3a05eb7597ade52a0c99b89c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / platform_context-0.5.0-py3-none-any.whl

Download URL platform_context-0.5.0-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
680bcdfdf37a63c3e4600a9b6f903d3835271a2fbbeea0b329e6729f08403bfa
BLAKE2b-256 checksum
How to use checksums
46b08a575e521eccf62fc858cf11ede7279531fe5c5be1280c6d5562930dba2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for platform-context 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page