Shared core components for BFAgent Hub ecosystem (Tenancy, Auth, Audit, Outbox)
Project description
bfagent-core
Shared core components for the BFAgent Hub ecosystem.
Features
- Tenancy: Multi-tenant support with subdomain resolution and Postgres RLS
- Request Context: Thread-safe context propagation (tenant_id, user_id, request_id)
- Audit: Audit event logging for compliance
- Outbox: Transactional outbox pattern for reliable event publishing
Installation
pip install bfagent-core
# or from git
pip install "bfagent-core @ git+https://github.com/achimdehnert/platform.git#subdirectory=packages/bfagent-core"
Usage
Request Context
from bfagent_core.context import get_context, set_tenant, set_user_id
# Set context (typically in middleware)
set_tenant(tenant_id=uuid, tenant_slug="demo")
set_user_id(user_id)
# Get context anywhere
ctx = get_context()
print(ctx.tenant_id, ctx.user_id, ctx.request_id)
Audit Events
from bfagent_core.audit import emit_audit_event
emit_audit_event(
tenant_id=tenant_id,
category="risk.assessment",
action="created",
entity_type="risk.Assessment",
entity_id=assessment.id,
payload={"title": assessment.title},
)
Outbox Pattern
from bfagent_core.outbox import emit_outbox_event
emit_outbox_event(
tenant_id=tenant_id,
topic="risk.assessment.created",
payload={"assessment_id": str(assessment.id)},
)
Postgres RLS
from bfagent_core.db import set_db_tenant
# Set tenant for RLS (in middleware)
set_db_tenant(tenant_id)
Django Integration
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...
"bfagent_core",
]
Add middleware:
MIDDLEWARE = [
...
"bfagent_core.middleware.RequestContextMiddleware",
"bfagent_core.middleware.SubdomainTenantMiddleware",
]
License
MIT
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
iil_bfagent_core-0.2.0.tar.gz
(33.4 kB
view details)
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_bfagent_core-0.2.0.tar.gz.
File metadata
- Download URL: iil_bfagent_core-0.2.0.tar.gz
- Upload date:
- Size: 33.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79185fc9cc08dcb8f8313d8de0c414a31784b10badb8fc166c4659818187fb91
|
|
| MD5 |
4e5b0208bfb3f7c713b47f192b3202ff
|
|
| BLAKE2b-256 |
86e389c3e16b9d2de715d5c9a19942615107a54a21d1927745596d77180df1e9
|
File details
Details for the file iil_bfagent_core-0.2.0-py3-none-any.whl.
File metadata
- Download URL: iil_bfagent_core-0.2.0-py3-none-any.whl
- Upload date:
- Size: 47.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d375126f6134b1a6d55597cb26b308b817f6406c45d77f215595b7a62dbad4e2
|
|
| MD5 |
cb9819a2c2699c15dfb1fd059d35b092
|
|
| BLAKE2b-256 |
62b3bc9b76f293e3800ef7c3cc283a2cacbb57be6bf48832d3d988dbae0c9bf1
|