skillfed

django-tenants

Tenant support for Django using PostgreSQL schemas.

django-tenants v3.14.0 958.4K downloads/30d#4,641 on PyPI1,882
Permissive license MIT Active released

What it is and what it does

django-tenants is a Django extension that implements the semi-isolated multitenancy pattern: one PostgreSQL database with separate schemas per tenant. It intercepts requests by hostname, routes them to the correct tenant schema, and makes all ORM queries operate transparently within that schema without requiring changes to your view code. The package manages schema creation, migration routing (shared vs. tenant-specific), and provides middleware to automatically set the PostgreSQL search path on each request.

You define a tenant model (e.g., Client) and a domain model to map hostnames to tenants. When a request arrives at tenant.example.com, the middleware looks up the tenant, sets the schema, and all subsequent database operations happen in that tenant's isolated space. This approach balances simplicity—minimal code changes needed—with performance benefits of shared connections and buffers compared to fully separate databases.

Use it for:

  • Build a SaaS platform where each customer's data must be isolated but served from a single Django instance
  • Implement different views or configurations per tenant while reusing the same codebase and database connection pool
  • Manage shared data (e.g., billing, user accounts) in the public schema while keeping customer-specific tables in tenant schemas
  • Scale horizontally by running multiple application instances against the same PostgreSQL database with automatic tenant routing

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Enables Django applications to serve multiple tenants from a single instance using PostgreSQL schemas, where each tenant's data is isolated in its own schema while sharing the application code.

Yes. django-tenants is production-stable (Development Status 5), actively maintained, has no known vulnerabilities, and solves a real architectural problem for SaaS applications. The single django dependency and permissive MIT license remove friction. Install if you need schema-based multitenancy on PostgreSQL; it requires Django 2+ and PostgreSQL, and you must be comfortable with PostgreSQL schema concepts.

Install

django-tenants on PyPI

pip

pip install django-tenants

uv

uv add django-tenants

poetry

poetry add django-tenants

Installing django-tenants

Before you install

Low install friction with a single runtime dependency on django. Actively maintained with recent releases and a stable codebase (1882 GitHub stars, last commit 2026-08-10).

License in practice

MIT license permits commercial use, modification, and distribution with minimal restrictions—suitable for proprietary SaaS applications.

Quickstart

# Install
pip install django-tenants

# In settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django_tenants.postgresql_backend',
        # ...
    }
}
MIDDLEWARE = (
    'django_tenants.middleware.main.TenantMainMiddleware',
    # ...
)
INSTALLED_APPS = [
    'django_tenants',
    # ...
]
TENANT_MODEL = "customers.Client"
TENANT_DOMAIN_MODEL = "customers.Domain"

# In models.py
from django_tenants.models import TenantMixin, DomainMixin

class Client(TenantMixin):
    name = models.CharField(max_length=100)

class Domain(DomainMixin):
    pass

# Run migrations
python manage.py migrate_schemas --shared

Requires PostgreSQL database backend and Django 2+; Python 3.10 or later.

Verify before relying

  • Whether the package handles tenant-specific migrations automatically or requires manual intervention
  • Performance characteristics under high tenant counts or concurrent request loads
  • Compatibility with Django's async views and async ORM features

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — django
Maintenance actively maintained — 9 days since the last release
Last repo commit
First released
Downloads 958,398/month — #4,641 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_tenants-3.14.0-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 5.2Framework :: Django :: 6.0Framework :: Django :: 6.1Programming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Software Development :: Libraries :: Python Modules

Tags

django multitenancy postgres schemassaas tenant isolation djangodjango multiple customers one instancepostgresql schema-based tenantsdjango tenant routing by domain
multitenancysaaspostgresql

More Python Modules packages