← Back to all products

Tenant Manager

$29

Multi-tenant management system with thread-local isolation, per-tenant config, and provisioning.

📁 9 files
PythonMarkdownReact

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 9 files

tenant-manager/ ├── LICENSE ├── README.md ├── examples/ │ └── basic_example.py ├── free-sample.zip ├── guide/ │ ├── 01_features.md │ ├── 02_quick-start.md │ └── 03_project-structure.md ├── index.html └── src/ └── main.py

📖 Documentation Preview README excerpt

Tenant Manager

A complete Python multi-tenant management system. Handles tenant isolation via thread-local context, per-tenant configuration, data partitioning, plan-based feature gating, member management, and admin cross-tenant operations — all built on Python's standard library.

Features

  • Tenant isolation — Thread-local context ensures requests never leak data between tenants
  • Context managerwith tenant_scope("tenant_id"): for scoped operations
  • Per-tenant config — Feature flags, user limits, storage limits, theming per tenant
  • Plan-based limits — Free/Starter/Pro/Enterprise tiers with auto-applied config
  • Data partitioning — All CRUD operations automatically scoped to current tenant
  • Member management — Add/remove users, role-based access (owner/admin/member/viewer)
  • Tenant lifecycle — Create, suspend, reactivate, upgrade plans
  • Admin operations — Cross-tenant queries and platform-wide statistics
  • JSON persistence — Save/load state for development

Requirements

  • Python 3.10+
  • No external dependencies (stdlib only)

Quick Start


python src/main.py --init-demo

# List tenants
curl http://localhost:8004/api/tenants

# Create a tenant
curl -X POST http://localhost:8004/api/tenants \
  -H "Content-Type: application/json" \
  -d '{"name": "My Company", "slug": "my-company", "owner_id": "user_1", "plan": "pro"}'

# Add a member
curl -X POST http://localhost:8004/api/tenants/<id>/members \
  -H "Content-Type: application/json" \
  -d '{"user_id": "user_2", "role": "admin"}'

# Platform stats
curl http://localhost:8004/api/admin/stats

API Endpoints

MethodPathDescription
GET/api/tenantsList all tenants
POST/api/tenantsCreate a new tenant
GET/api/tenants/:idGet tenant details + members
POST/api/tenants/:id/membersAdd a member
POST/api/tenants/:id/upgradeUpgrade tenant plan
GET/api/admin/statsPlatform-wide statistics

Project Structure


tenant-manager/

*... continues with setup instructions, usage examples, and more.*

📄 Code Sample .py preview

examples/basic_example.py#!/usr/bin/env python3 """ Tenant Manager — Basic Usage Example ====================================== Demonstrates multi-tenant data isolation, member management, and the tenant_scope context manager. Run: python3 basic_example.py """ from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src")) from main import TenantStore, tenant_scope, get_current_tenant_id def main() -> None: print("=== Tenant Manager — Basic Example ===\n") store = TenantStore(data_dir=Path("/tmp/tenant-demo")) # --- 1. Create tenants --- acme = store.create_tenant("Acme Corp", "acme-corp", "user_alice", "pro") widgets = store.create_tenant("Widget Labs", "widget-labs", "user_bob", "starter") print(f"Created: {acme.name} (plan={acme.plan}, max_users={acme.config.max_users})") print(f"Created: {widgets.name} (plan={widgets.plan}, max_users={widgets.config.max_users})") # --- 2. Add members --- store.add_member(acme.id, "user_charlie", "admin") store.add_member(acme.id, "user_diana", "member") print(f"\nAcme members: {len(store.get_members(acme.id))}") # --- 3. Data isolation with tenant_scope --- print("\n--- Data Isolation Demo ---")
Buy Now — $29 Back to Products