django-two-factor-auth
Complete Two-Factor Authentication for Django
What it is and what it does
Django Two-Factor Authentication is a complete 2FA solution built on top of Django's authentication framework and the django-otp one-time password library. It integrates seamlessly into existing Django projects and lets users authenticate through multiple channels: one-time passwords (TOTP), SMS text messages, voice calls, token generator apps like Google Authenticator, or hardware tokens such as YubiKey.
The package handles the full authentication flow, from user enrollment through verification, and is designed to mirror the user experience of Google's Two-Step Authentication. It includes support for multiple languages and works with Django 4.2 through 5.1 on Python 3.9–3.13. An example app is available for testing most features, and documentation is comprehensive.
Use it for:
- Add SMS or call-based 2FA to a Django web application for user account security.
- Integrate TOTP-based authentication (Google Authenticator, Authy) into an existing Django login flow.
- Support hardware security keys (YubiKey) for high-security user accounts.
- Build a multi-channel authentication system where users choose their preferred 2FA method.
- Enhance Django admin or staff portals with mandatory two-factor verification.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds complete two-factor authentication to Django projects, supporting authentication via one-time passwords, SMS, call, token generator apps, and hardware tokens like YubiKey.
Yes. This is a mature, actively maintained package (1876 GitHub stars, recent commits) with no known vulnerabilities, low install friction, and permissive licensing. It solves a critical security problem for Django projects and integrates cleanly with Django's built-in auth framework. Use it when you need production-grade 2FA for a Django application.
Install
django-two-factor-auth on PyPI
pip
pip install django-two-factor-authuv
uv add django-two-factor-authpoetry
poetry add django-two-factor-authInstalling django-two-factor-auth
Before you install
Low friction installation with a pure-Python wheel. Active maintenance with recent commits and no known vulnerabilities. Supports current Django versions (4.2, 5.0, 5.1, 5.2) and Python 3.9–3.13.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
Quickstart
pip install django-two-factor-auth
from django_otp.plugins.otp_totp.models import StaticDevice
from django_two_factor_auth.views import LoginView
# Add to Django settings.INSTALLED_APPS:
# 'django_otp',
# 'django_two_factor_auth',
Requires Django 4.2+ and Python 3.9+. Depends on django-otp, qrcode, django-phonenumber-field, and django-formtools as runtime dependencies.
Verify before relying
- Whether Twilio SMS integration is fully functional or requires additional setup beyond the package itself.
- Performance characteristics when handling high volumes of authentication requests.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — Django, django_otp, qrcode, django-phonenumber-field, django-formtools |
| Maintenance | actively maintained — 321 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,111,562/month — #2,750 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_two_factor_auth-1.18.1-py3-none-any.whl
Keywords: django, two-factor
Tags
More Security packages
Provides Python bindings to the FreeDesktop.org…
permissive · top 1,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
joserfcjoserfc implements JOSE standards (JWS, JWE,…
permissive · top 1,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
argon2-cffi-bindingsProvides low-level CFFI bindings to the…
permissive · top 1,000 on PyPI
adalADAL for Python authenticates applications with…
permissive · top 1,000 on PyPI
authyPython client for the Twilio Authy two-factor…
permissive · top 15,000 on PyPI
django-otpAdds one-time password (OTP) support to Django…
permissive · top 5,000 on PyPI
django-allauth-2faAdds two-factor authentication to…
permissive · top 15,000 on PyPI
yubico-clientVerifies Yubico One Time Passwords (OTPs) using…
permissive · top 15,000 on PyPI
PyOTPPyOTP generates and verifies one-time passwords…
permissive · top 1,000 on PyPI
django-user-sessionsReplaces Django's opaque session backend with…
permissive · top 15,000 on PyPI
google-reauthProvides two-factor authentication reauth…
permissive · top 5,000 on PyPI
django-otp-webauthnAdds WebAuthn Passkey support to Django OTP,…
permissive · top 15,000 on PyPI
oathtoolGenerates one-time passwords (TOTP codes) from…
permissive · top 15,000 on PyPI
django-registrationProvides user registration workflows for Django…
permissive · top 15,000 on PyPI