Shared FastAPI/Starlette infrastructure for Soorma backend services
Project description
soorma-service-common
Shared FastAPI/Starlette infrastructure library for Soorma backend services.
Provides three cross-cutting concerns for all services (Memory, Tracker, Registry, Event Service):
- Identity extraction —
TenancyMiddlewarevalidates bearer tokens and projects platform-tenant, service-tenant, and service-user identity intorequest.stateon secured requests. - RLS activation —
create_get_tenanted_dbfactory produces a FastAPI dependency that calls PostgreSQLset_configfor all three session variables (transaction-scoped) before yielding the DB session, activating Row-Level Security policies. - GDPR deletion contract —
PlatformTenantDataDeletionabstract base class defines the erasure interface; concrete implementations live in each service.
Usage
# In your service's core/dependencies.py
from soorma_service_common import (
create_get_tenanted_db,
create_get_tenant_context,
)
from my_service.core.database import get_db
get_tenanted_db = create_get_tenanted_db(get_db)
get_tenant_context = create_get_tenant_context(get_tenanted_db)
# In your service's main.py
from soorma_service_common import TenancyMiddleware
app.add_middleware(TenancyMiddleware)
# In your route handlers
from my_service.core.dependencies import get_tenant_context
from soorma_service_common import TenantContext
@router.post("/items")
async def create_item(payload: ItemCreate, ctx: TenantContext = Depends(get_tenant_context)):
return await service.create(ctx.db, ctx.platform_tenant_id, ctx.service_tenant_id, ctx.service_user_id, payload)
Constraints
- MUST NOT be imported by
soorma-commonorsdk/python— contains FastAPI/Starlette dependencies incompatible with SDK clients. platform_tenant_idflows from validated request identity or Event Service injection — never as a per-call API parameter.
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 soorma_service_common-0.9.1.tar.gz.
File metadata
- Download URL: soorma_service_common-0.9.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4354298d79741985edaa8f75ce1e28e0809edd1d1ab4bc26eca652c9efba2d45
|
|
| MD5 |
40e0cf334bc08d5caba90be6a7310bba
|
|
| BLAKE2b-256 |
71ad473ebbb635a29f4c24c8739b60bd5dd634580f011a4f6d6e30779a859f00
|
File details
Details for the file soorma_service_common-0.9.1-py3-none-any.whl.
File metadata
- Download URL: soorma_service_common-0.9.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c59bddcd07ba7574fac54cbdafbbda61593d9c6f669ceeb939208ef8f7f6aa4
|
|
| MD5 |
02fd150a913710d51709a4e4318679a9
|
|
| BLAKE2b-256 |
3a2e25a046fc3d37aafec2400f91c58b87693fbf5eeb275f6ed91d14a5b70bb3
|