fastapi-tenants
A multi-tenancy solution for FastAPI with support for database-per-tenant, schema-per-tenant, and row-level tenancy strategies.
✨ Features
- Flexible strategies → database-per-tenant, schema-per-tenant, row-level.
- Tenant-aware middleware → resolve tenant from headers, subdomains, or tokens.
- DB session management → per-tenant scoped sessions.
- Pluggable design → extend strategies or authentication as needed.
- FastAPI-first → built for dependency injection and async support.
📦 Installation
pip install fastapi-tenants
Optional extras:
pip install "fastapi-tenants[postgres]"
pip install "fastapi-tenants[mysql]"
🚀 Quick Start
from fastapi import FastAPI, Depends
from fastapi_tenants import TenancyMiddleware, get_tenant_session
app = FastAPI()
# Enable tenancy
app.add_middleware(
TenancyMiddleware,
strategy="schema", # or "database", "row"
header="X-Tenant-ID"
)
@app.get("/users")
def list_users(session = Depends(get_tenant_session)):
return session.query(User).all()
📚 Roadmap
- Schema-based tenancy ✅
- Database-per-tenant support
- Row-level tenancy
- Multi-backend support (Postgres, MySQL, SQLite)
- Example apps & docs
🤝 Contributing
Contributions are welcome! Check out CONTRIBUTING.md (coming soon).
📜 License
MIT License © 2025 Kapil Dagur
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_tenants-0.0.2.tar.gz
(4.2 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 fastapi_tenants-0.0.2.tar.gz.
File metadata
- Download URL: fastapi_tenants-0.0.2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1849f81029db5b3a1b7d41301a92f839ebf78f0c9290910d88233b5f55e9119c
|
|
| MD5 |
6f9c3c23cf8ed7f89e64f41ba777a60a
|
|
| BLAKE2b-256 |
5044fad27e763e145ac110e0620ea8229a850ce4b4e781aff9075b7e64553d2d
|
File details
Details for the file fastapi_tenants-0.0.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_tenants-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da1647d10e332311f3139ce7b9c7580f7f94bbb26cf22a681a48ba0ca486a791
|
|
| MD5 |
59be3c9e7763c0d338b99326fffd5365
|
|
| BLAKE2b-256 |
6370aff0bee343fad32ae1061d758e6bc34555e389a847969acdd23386576d3c
|