--- id: django-multitenant version: "4.1.1" license: unclear license_treatment: permissive maintenance: active --- # django-multitenant — Django Library to Implement Multi-tenant databases License: permissive · Maintenance: active · Downloads: 169.6K/mo ## 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 above — 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 pip install django-multitenant uv add django-multitenant poetry add django-multitenant ## Installing 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: unspecified - Install friction: low - Maintenance: active - Downloads: 169.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django multi-tenant database, tenant isolation orm, citus django integration, shared table multi-tenancy, postgres tenant routing, django tenant context, saas database scaling, multi-tenant, saas, citus [View on SkillFed](https://skillfed.io/packages/django-multitenant) · [View on PyPI](https://pypi.org/project/django-multitenant/)