Metadata-Version: 2.4
Name: iil-platform-context
Version: 0.5.1
Summary: Shared platform foundation for all Django projects (Context, Tenancy, Audit, Outbox)
Author-email: Achim Dehnert <achim@dehnert.com>
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django :: 5.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Requires-Dist: django<6.0,>=5.0
Provides-Extra: dev
Requires-Dist: factory-boy>=3.3; extra == 'dev'
Requires-Dist: pytest-django>=4.8; extra == 'dev'
Requires-Dist: pytest-mock>=3.12; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: temporal
Requires-Dist: temporalio>=1.7.0; extra == 'temporal'
Provides-Extra: tenants
Requires-Dist: django-tenants>=3.6; extra == 'tenants'
Requires-Dist: httpx>=0.27; extra == 'tenants'
Requires-Dist: tenant-schemas-celery>=2.0; extra == 'tenants'
Provides-Extra: testing
Requires-Dist: factory-boy>=3.3; extra == 'testing'
Requires-Dist: pytest-django>=4.8; extra == 'testing'
Requires-Dist: pytest-mock>=3.12; extra == 'testing'
Requires-Dist: pytest>=8.0; extra == 'testing'
Description-Content-Type: text/markdown

# 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

```bash
pip install -e packages/platform-context
```

Add to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    ...
    "platform_context",
]
```

## Usage

```python
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.
