Skip to main content

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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_tenants-0.0.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for fastapi_tenants-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1849f81029db5b3a1b7d41301a92f839ebf78f0c9290910d88233b5f55e9119c
MD5 6f9c3c23cf8ed7f89e64f41ba777a60a
BLAKE2b-256 5044fad27e763e145ac110e0620ea8229a850ce4b4e781aff9075b7e64553d2d

See more details on using hashes here.

File details

Details for the file fastapi_tenants-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_tenants-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da1647d10e332311f3139ce7b9c7580f7f94bbb26cf22a681a48ba0ca486a791
MD5 59be3c9e7763c0d338b99326fffd5365
BLAKE2b-256 6370aff0bee343fad32ae1061d758e6bc34555e389a847969acdd23386576d3c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page