Registry / database / django-multitenant

django-multitenant

JSON →
library4.1.1pypypiunverified

Django library to implement multi-tenant databases, primarily targeting Citus (PostgreSQL extension for horizontal scaling). Supports Django 3.2 to 5.0 with Python 3.8+. Provides mixins, managers, and utilities to isolate tenant data via a tenant_id column. Release cadence is irregular, with the latest stable version 4.1.1 from 2024.

pip install django-multitenant
INSTALL
IMPORT
SIG · DJANGO-MULTITENANT
D
django-multitenant
databasepythonv4.1.1
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v4.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TenantModelMixin
✓ from django_multitenant.mixins import TenantModelMixin
✗ from django_multitenant.mixins import TenantModelMixin

Define a Tenant model and a tenant-aware model using TenantModelMixin.

import os from django.db import models from django_multitenant.mixins import TenantModelMixin from django_multitenant.models import TenantModel class Tenant(models.Model): tenant_id = models.AutoField(primary_key=True) name = models.CharField(max_length=100) class Project(TenantModelMixin, models.Model): tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE) name = models.CharField(max_length=100) class Meta: app_label = 'myapp' # In your settings, ensure DATABASES and MIDDLEWARE are configured # See https://django-multitenant.readthedocs.io/
Debug
Known issues
breakingIn v3.0.0, TenantModelMixin was moved from django_multitenant.models to django_multitenant.mixins. Old imports will break.
fix
Change import to from django_multitenant.mixins import TenantModelMixin
affects: <3.0.0
gotchaTenantModelMixin must be listed before models.Model in the class definition to avoid MRO issues.
fix
class MyModel(TenantModelMixin, models.Model): ...
affects: all
gotchaWhen using ManyToMany fields between tenant models, the intermediate table may not include the tenant column automatically. You must define a through model with tenant_id.
fix
Explicitly define a through model with a ForeignKey to the tenant model.
affects: all
deprecatedThe TenantModel base class is deprecated in favor of TenantModelMixin + models.Model.
fix
Use TenantModelMixin with models.Model instead of inheriting TenantModel.
affects: >=3.0.0
Upgrade
Version history
4.1.1latest on PyPI · released Dec 18, 2023
Audit
Dependencies
DjangorequiredCore dependency, supports 3.2+
Agent activity
4 hits · last 30 days
node
4
Resources
django-multitenant — pip install django-multitenant · libregistry