skillfed

swapper

The unofficial Django swappable models API.

swapper v1.4.0 522.8K downloads/30d#6,200 on PyPI250
Permissive license MIT Active released

What it is and what it does

Swapper is a library that wraps Django's built-in but undocumented swappable models mechanism—the same system Django uses internally for auth.User—and exposes it as a stable API for third-party library authors. It lets you design reusable Django apps whose core models can be replaced entirely by end users, without forcing you to use abstract base classes or accept concrete models that cannot be customized.

The library provides functions to declare which models are swappable, load the correct model class at runtime (whether default or user-provided), and handle foreign keys and migrations correctly. This is primarily a tool for library authors; end users of your app typically configure a single setting to swap models, similar to how they would set AUTH_USER_MODEL.

Use it for:

  • Building a reusable Django package where users need to extend or replace core models with custom fields or logic.
  • Implementing multi-tenant or white-label SaaS applications where each tenant's model structure must be customizable.
  • Creating extensible authentication or user management libraries that don't force a single User model design.
  • Handling migration dependencies correctly when your library has multiple levels of related swappable models.
  • Allowing end users to swap models without requiring them to fork or patch your library code.

Worth the install?

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

Swapper provides an API for Django's undocumented swappable models feature, allowing library authors to make their app's models replaceable by end users without requiring abstract base classes or concrete model constraints.

Yes. Swapper is production-stable (Development Status 5), actively maintained, has no external dependencies, and solves a real problem for library authors building customizable Django apps. The MIT license imposes no restrictions. Install it if you are authoring a reusable Django package that needs model extensibility; skip it if you are building a single application.

Install

swapper on PyPI

pip

pip install swapper

uv

uv add swapper

poetry

poetry add swapper

Installing swapper

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained with recent commits and stable production status across Django 2.0 through 5.0.

License in practice

MIT license is permissive; you may use, modify, and distribute swapper freely in proprietary or open-source projects without restriction.

Quickstart

pip install swapper

# In your reusable app's models.py:
import swapper

class Parent(models.Model):
    class Meta:
        swappable = swapper.swappable_setting('myapp', 'Parent')

# In views or other code:
Parent = swapper.load_model('myapp', 'Parent')

Requires Django to be installed and configured; swapper.load_model() should not be called until after Django's model system has fully initialized.

Verify before relying

  • Whether swapper works with Django versions earlier than 2.0 or later than 5.0 beyond what classifiers declare.
  • Performance characteristics when swapping deeply nested model hierarchies with multiple foreign keys.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 730 days since the last release
Last repo commit
First released
Downloads 522,809/month — #6,200 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: swapper-1.4.0-py2.py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 2.0Framework :: Django :: 2.1Framework :: Django :: 2.2Framework :: Django :: 3.0Framework :: Django :: 3.1Framework :: Django :: 3.2Framework :: Django :: 4.0Framework :: Django :: 4.2Framework :: Django :: 5.0License :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

django swappable modelsdjango model customizationdjango model replacementreusable django appsdjango auth user patterndjango model inheritancedjango app extensibility
django-extensionmodel-customizationlibrary-authoring

More Application Frameworks packages

fastapi

FastAPI is a Python web framework for building…

permissive · top 100 on PyPI

annotated-doc

Provides a way to document function parameters,…

permissive · top 100 on PyPI

textual

Textual is a Python framework for building…

permissive · top 100 on PyPI

typer

Typer builds command-line applications from…

permissive · top 1,000 on PyPI

mcp

Build and connect to Model Context Protocol…

permissive · top 1,000 on PyPI

Werkzeug

Werkzeug is a WSGI utility library providing…

permissive · top 1,000 on PyPI

django-reverse-admin

Adds reverse inline support to Django admin for…

permissive · top 15,000 on PyPI

rest-framework-generic-relations

Provides Django REST Framework serializers that…

permissive · top 15,000 on PyPI

django-ordered-model

Adds ordering and reordering capabilities to…

permissive · top 15,000 on PyPI

drf-writable-nested

Extends Django REST Framework serializers to…

permissive · top 15,000 on PyPI

django-model-utils

Provides reusable model mixins and field…

permissive · top 5,000 on PyPI

django-add-default-value

Provides a Django migration operation to set…

permissive · top 15,000 on PyPI

django-deprecate-fields

Provides a decorator to mark Django model…

permissive · top 5,000 on PyPI

django-nonrelated-inlines

Provides Django admin inline classes that let…

permissive · top 15,000 on PyPI

django-modelcluster

django-modelcluster extends Django models to…

permissive · top 5,000 on PyPI

django-appconf

Provides a base class for Django apps to define…

permissive · top 5,000 on PyPI