← Back to all products
$29
Tenant Manager
Multi-tenant management system with thread-local isolation, per-tenant config, and provisioning.
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 manager —
with 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
| Method | Path | Description |
|---|---|---|
| GET | /api/tenants | List all tenants |
| POST | /api/tenants | Create a new tenant |
| GET | /api/tenants/:id | Get tenant details + members |
| POST | /api/tenants/:id/members | Add a member |
| POST | /api/tenants/:id/upgrade | Upgrade tenant plan |
| GET | /api/admin/stats | Platform-wide statistics |
Project Structure
tenant-manager/
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/main.py
#!/usr/bin/env python3
"""
Tenant Manager — Multi-Tenant System
======================================
A complete multi-tenant management system for SaaS applications. Handles
tenant isolation, per-tenant configuration, data partitioning, tenant-scoped
queries, and cross-tenant admin operations.
Zero dependencies. Just run: python3 main.py
Part of the SaaS Starter collection by DataNest.
License: MIT
"""
from __future__ import annotations
import argparse
import json
import logging
import os
import threading
import time
import uuid
from contextlib import contextmanager
from dataclasses import asdict, dataclass, field
from datetime import datetime, timezone
from http.server import BaseHTTPRequestHandler, HTTPServer
from pathlib import Path
from typing import Any, Generator, Optional
from urllib.parse import parse_qs, urlparse
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 8004
DATA_DIR = Path("./tenant-data")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s — %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
)
logger = logging.getLogger("tenant-manager")
# ---------------------------------------------------------------------------
# Tenant Context — Thread-Local Isolation
# ... 479 more lines ...