django-multitenant
Django Library to Implement Multi-tenant databases
What it is and what it does
django-multitenant is a Django library that implements multi-tenant database patterns where all tenants share the same tables but are isolated by a tenant_id column. It automatically injects tenant context into queries, allowing databases like Postgres+Citus to route queries efficiently to the correct shard or node without requiring separate databases or schemas per tenant.
The library provides two integration patterns: inherit from TenantModel or use TenantModelMixin with your existing Django models. It replaces standard ForeignKey with TenantForeignKey to maintain tenant relationships and includes middleware utilities to set tenant context per request. This approach scales horizontally by letting the database layer handle tenant-aware query routing rather than application-level filtering.
Use it for:
- Building SaaS applications where multiple customers share infrastructure but need data isolation at the database level.
- Scaling Django apps on Postgres+Citus by automating tenant_id inclusion in all queries without manual filtering.
- Implementing composite foreign keys with tenant_id at the database layer to enforce referential integrity across tenant boundaries.
- Setting up multi-tenant middleware that automatically scopes all ORM operations to the current request's tenant.
- Migrating monolithic Django apps to a shared-table multi-tenant architecture without rewriting query logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds multi-tenant database support to Django by automatically scoping queries to a tenant context, enabling efficient query routing in distributed databases like Postgres+Citus.
Yes. The package is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and solves a specific architectural problem (shared-table multi-tenancy) that would otherwise require manual tenant filtering throughout your codebase. Install it if you are building a multi-tenant Django application on Postgres+Citus or similar distributed databases.
Install
django-multitenant on PyPI
pip
pip install django-multitenantuv
uv add django-multitenantpoetry
poetry add django-multitenantInstalling django-multitenant
Before you install
Low install friction with no runtime dependencies. Active maintenance with recent commits and a stable release history since 2017; last release was 2023-12-18.
License in practice
MIT license (permissive) allows commercial use, modification, and distribution with minimal restrictions.
Quickstart
pip install django-multitenant
from django_multitenant.models import TenantModel
from django_multitenant.fields import TenantForeignKey
from django_multitenant.utils import set_current_tenant
class Store(TenantModel):
name = models.CharField(max_length=50)
class TenantMeta:
tenant_field_name = "id"
class Product(TenantModel):
store = models.ForeignKey(Store)
name = models.CharField(max_length=255)
class TenantMeta:
tenant_field_name = "store_id"
set_current_tenant(store_instance)
products = Product.objects.all() # Automatically filtered by tenant
Requires Django to be installed separately; ensure your Django version matches the supported versions (3.2, 4.0, 4.1, or 4.2) for your Python version (3.7–3.11).
Verify before relying
- Whether the package requires Django to be installed separately or if it's specified as a dependency elsewhere
- Exact Python version support beyond the classifiers (3.7, 3.8, 3.9, 3.10, 3.11 listed)
- Performance characteristics when used with very large tenant datasets
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 970 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 169,585/month — #10,416 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_multitenant-4.1.1-py3-none-any.whl
Keywords: citus, django, multi, tenantdjango, postgres, multi-tenant
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-tenantsEnables Django applications to serve multiple…
permissive · top 5,000 on PyPI
tenant-schemas-celeryIntegrates Celery task queuing with…
permissive · top 15,000 on PyPI
django-pgviews-reduxAdds first-class PostgreSQL view support to…
unclear · top 15,000 on PyPI
django-ordered-modelAdds ordering and reordering capabilities to…
permissive · top 15,000 on PyPI
django-tree-queriesQuery hierarchical tree structures in Django…
permissive · top 15,000 on PyPI
django-add-default-valueProvides a Django migration operation to set…
permissive · top 15,000 on PyPI
django-reverse-adminAdds reverse inline support to Django admin for…
permissive · top 15,000 on PyPI
django-pgtriggerdjango-pgtrigger lets you define PostgreSQL…
permissive · top 5,000 on PyPI
django-querycountDjango middleware that logs the number of…
permissive · top 15,000 on PyPI