skillfed

django-multitenant

Django Library to Implement Multi-tenant databases

django-multitenant v4.1.1 169.6K downloads/30d#10,416 on PyPI823
Permissive license Active released

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-multitenant

uv

uv add django-multitenant

poetry

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 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Database

Tags

django multi-tenant databasetenant isolation ormcitus django integrationshared table multi-tenancypostgres tenant routingdjango tenant contextsaas database scaling
multi-tenantsaascitus

More Database packages