swapper
The unofficial Django swappable models API.
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 swapperuv
uv add swapperpoetry
poetry add swapperInstalling 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
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
django-reverse-adminAdds reverse inline support to Django admin for…
permissive · top 15,000 on PyPI
rest-framework-generic-relationsProvides Django REST Framework serializers that…
permissive · top 15,000 on PyPI
django-ordered-modelAdds ordering and reordering capabilities to…
permissive · top 15,000 on PyPI
drf-writable-nestedExtends Django REST Framework serializers to…
permissive · top 15,000 on PyPI
django-model-utilsProvides reusable model mixins and field…
permissive · top 5,000 on PyPI
django-add-default-valueProvides a Django migration operation to set…
permissive · top 15,000 on PyPI
django-deprecate-fieldsProvides a decorator to mark Django model…
permissive · top 5,000 on PyPI
django-nonrelated-inlinesProvides Django admin inline classes that let…
permissive · top 15,000 on PyPI
django-modelclusterdjango-modelcluster extends Django models to…
permissive · top 5,000 on PyPI
django-appconfProvides a base class for Django apps to define…
permissive · top 5,000 on PyPI