django-tenants
Tenant support for Django using PostgreSQL schemas.
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-tenantsuv
uv add django-tenantspoetry
poetry add django-tenantsInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
django-multitenantAdds multi-tenant database support to Django by…
permissive · top 15,000 on PyPI
tenant-schemas-celeryIntegrates Celery task queuing with…
permissive · top 15,000 on PyPI
duplocloud-clientCLI and Python SDK for managing DuploCloud…
permissive · top 15,000 on PyPI
dj-materialized-viewsManages PostgreSQL materialized views through a…
permissive · top 15,000 on PyPI
django-db-connection-poolProvides connection pooling for Django database…
permissive · top 15,000 on PyPI
schemainspectInspects PostgreSQL database schemas to extract…
permissive · top 15,000 on PyPI
migramigra compares PostgreSQL database schemas and…
permissive · top 15,000 on PyPI
django-pgviews-reduxAdds first-class PostgreSQL view support to…
unclear · top 15,000 on PyPI
django-postgres-copyProvides Django ORM integration for…
permissive · top 5,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI