Two-factor authentication (2FA) is becoming a standard requirement for modern applications, especially for APIs that use JWT authentication or separate frontend/backend architectures.
While working on Django REST Framework projects, I wanted a lightweight and API-focused way to add TOTP authentication without depending heavily on template-based flows or admin integrations.
So I built django-totp .
It is a reusable Django package that provides:
TOTP enrollment
QR generation
backup recovery codes
encrypted secret storage
DRF endpoints
helper utilities for multi-step authentication flows
PyPI: django-totp
Requirements
Python 3.12+
Django 5.0+
Django REST Framework 3.15+
Installation
Install the package from PyPI:
pip install django-totp
Enter fullscreen mode
Exit fullscreen mode
Add the apps to your Django settings:
INSTALLED_APPS = [ # Django apps...…