Production-ready multi-tenant SaaS toolkit for FastHTML applications with authentication, billing, and integrations
Project description
🚀 fh-saas
⚡ Quick Start
1. Install
pip install fh-saas
2. Configure Environment
# .env file
DB_TYPE=POSTGRESQL
DB_USER=postgres
DB_PASS=your_password
DB_HOST=localhost
DB_NAME=app_host
# Optional integrations
STRIPE_SECRET_KEY=sk_...
RESEND_API_KEY=re_...
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
3. Initialize Your App
from fh_saas.db_host import HostDatabase, GlobalUser, TenantCatalog, Membership, gen_id, timestamp
from fh_saas.db_tenant import get_or_create_tenant_db
from fh_saas.utils_db import register_tables, create_indexes
from fh_saas.utils_log import configure_logging
# Configure logging (once at startup)
configure_logging()
# Connect to host database
host_db = HostDatabase.from_env()
# Create a new user
user = GlobalUser(
id=gen_id(),
email="founder@startup.com",
oauth_id="google_abc123",
created_at=timestamp()
)
host_db.global_users.insert(user)
# Create a tenant for their organization
tenant = TenantCatalog(
id=gen_id(),
name="Acme Corp",
db_url="postgresql://...",
created_at=timestamp()
)
host_db.tenant_catalogs.insert(tenant)
# Link user to tenant as owner
membership = Membership(
id=gen_id(),
user_id=user.id,
tenant_id=tenant.id,
profile_id=gen_id(),
role="owner",
created_at=timestamp()
)
host_db.memberships.insert(membership)
host_db.commit()
4. Work with Tenant Data
# Get tenant's isolated database
tenant_db = get_or_create_tenant_db(tenant.id, tenant.name)
# Define your app's data models
class Project:
id: str
name: str
status: str = "active"
created_at: str
class Task:
id: str
project_id: str
title: str
completed: bool = False
# Register tables (creates if not exist)
tables = register_tables(tenant_db, [
(Project, "projects", "id"),
(Task, "tasks", "id"),
])
# Add indexes for performance
create_indexes(tenant_db, [
("tasks", ["project_id"], False, None),
("tasks", ["completed"], False, None),
])
# Use the tables
projects = tables["projects"]
projects.insert(Project(id=gen_id(), name="Launch MVP", created_at=timestamp()))
tenant_db.conn.commit()
📚 Documentation Guide
| Section | What You'll Learn |
| 📦 Core | |
| Multi-Tenant Setup | Host database, user management, tenant registry |
| Tenant Databases | Isolated databases per tenant, connection pooling |
| Table Management | Create tables & indexes from dataclasses |
| 🔌 Integrations | |
| HTTP Client | REST APIs with retries, rate limiting, auth |
| GraphQL Client | Streaming pagination for large datasets |
| Webhooks | Receive & verify external webhooks |
| ⚙️ Data Pipeline | |
| Background Tasks | Async job execution |
| Data Transforms | JSON → Polars → Database pipeline |
| API → DB Sync | End-to-end external data sync |
| 🛠️ Utilities | |
| SQL Helpers | Database type detection, query builders |
| Logging | Configurable logging for all modules |
| Authentication | OAuth flows (Google, GitHub) |
| Email Sending | Transactional emails via Resend |
| 📣 Content | |
| Blog Publishing | Markdown blog with frontmatter |
| SEO & Sitemaps | Sitemap generation, meta tags |
| Workflow Engine | Multi-step automation |
🛠️ Developer Guide
This project uses nbdev for literate
programming. The source of truth is in the nbs/ notebooks.
Development Setup
# Clone and install in dev mode
git clone https://github.com/abhisheksreesaila/fh-saas.git
cd fh-saas
pip install -e .
# Make changes in nbs/ directory, then compile
nbdev_prepare
📦 Installation
# From PyPI (recommended)
pip install fh-saas
# From GitHub (latest)
pip install git+https://github.com/abhisheksreesaila/fh-saas.git
GitHub · PyPI · Documentation
🤖 For AI Assistants: Download llms-ctx.txt — Complete API documentation for LLMs
🤖 AI Assistant Context
For AI coding assistants (GitHub Copilot, Claude, ChatGPT, Cursor, etc.), download the complete API documentation:
📥 Download llms-ctx.txt — Complete fh-saas documentation in LLM-friendly format
How to use:
- Download the context file
- Add to your AI assistant’s instructions/knowledge base
- Get accurate code suggestions for fh-saas APIs
This file contains all module documentation, examples, and API signatures formatted for optimal LLM understanding.
🤝 Contributing
Contributions are welcome! Please check the GitHub repository for issues and discussions.
🤖 AI Assistant Context
For AI coding assistants (GitHub Copilot, Claude, ChatGPT, Cursor, etc.), download the complete API documentation:
📥 Download llms-ctx.txt
What’s included: - Complete module documentation and API signatures - Code examples and usage patterns - Multi-tenant architecture patterns - Authentication and security flows - Data pipeline implementations
How to use: 1. Download the llms-ctx.txt file 2. Add it to your AI
assistant’s project context or instructions 3. Get accurate,
context-aware code suggestions for fh-saas
This consolidated context file (~500KB) contains all documentation formatted for optimal LLM understanding, enabling your AI assistant to provide precise help with fh-saas APIs.
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 fh_saas-0.9.3.tar.gz.
File metadata
- Download URL: fh_saas-0.9.3.tar.gz
- Upload date:
- Size: 40.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5a6089a14483ec264e919ecc3347618dccc6bd0cad2de30fe57fdd08332a3f2
|
|
| MD5 |
73b2044d1cc011f9d01f48895d39f0c9
|
|
| BLAKE2b-256 |
e7ccfa7c277d196fa3482c25ab805c0cbffe69e98013679c7e2ff3ac1f8da635
|
File details
Details for the file fh_saas-0.9.3-py3-none-any.whl.
File metadata
- Download URL: fh_saas-0.9.3-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
477268206c04155229d2ab0cbb308a9463c21a5ba6591b5c3fd16fcfcce0a912
|
|
| MD5 |
e4467173584d1685343115e6fa7267a5
|
|
| BLAKE2b-256 |
023bd3f6c57f2c973e1cc9a3e0805f6be3a4c80f677a8c2565b55a298e08fe2a
|