Registry / auth-security / django-otp

django-otp

JSON →
library1.7.0pypypi✓ verified 28d ago

django-otp is a pluggable framework designed to integrate two-factor authentication (2FA) into Django projects using one-time passwords (OTPs). It provides the core framework and common OTP algorithms (HOTP, TOTP), allowing developers to build custom 2FA solutions or leverage existing plugins. The current version is 1.7.0, and the project maintains a healthy release cadence with active maintenance.

pip install django-otp
INSTALL
IMPORT
SIG · DJANGO-OTP
D
django-otp
auth-securitypythonv1.7.0
Install
3.6s avg
Import
861ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.896s · 67MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.6s · import 0.826s · 68MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

device_classes
✓ from django_otp import device_classes
✗ from django_otp.models import Device
devices_for_user
✓ from django_otp import devices_for_user
verify_token
✓ from django_otp import verify_token

This quickstart outlines the essential steps to integrate `django-otp` into a Django project. It involves adding `django_otp` and at least one OTP plugin (e.g., `otp_totp`) to `INSTALLED_APPS` and enabling `OTPMiddleware`. For admin site integration, assign `OTPAdminSite` to `admin.site.__class__`. Remember to run `python manage.py migrate` after updating `INSTALLED_APPS` to create necessary database tables.

# settings.py INSTALLED_APPS = [ # ... other Django apps 'django_otp', 'django_otp.plugins.otp_totp', # Example: Time-based One-Time Passwords # 'django_otp.plugins.otp_hotp', # Example: HMAC-based One-Time Passwords # ... other OTP plugins (e.g., django-otp-sms) ] MIDDLEWARE = [ # ... other Django middleware 'django_otp.middleware.OTPMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', # Ensure this is before OTPMiddleware # ... ] # urls.py (example for admin integration) from django.contrib import admin from django.urls import path from django_otp.admin import OTPAdminSite admin.site.__class__ = OTPAdminSite urlpatterns = [ path('admin/', admin.site.urls), ] # After configuring, run migrations: # python manage.py migrate
Debug
Known issues
breakingOlder versions of django-otp have dropped support for legacy Python and Django versions. For instance, v0.3.11 dropped Python 2.6 and Django 1.4. The current version (1.7.0) explicitly requires Python >=3.8. Ensure your environment meets the `requires_python` specification.
fix
Upgrade your Python and Django versions to meet the minimum requirements of the `django-otp` version you intend to use (e.g., Python >=3.8 for 1.7.0).
affects: <= 1.0
gotchaFailing to add `django_otp.middleware.OTPMiddleware` to your `MIDDLEWARE` setting or placing it incorrectly (it should typically come after `AuthenticationMiddleware`) will prevent OTP verification from functioning correctly.
fix
Add `'django_otp.middleware.OTPMiddleware'` to your `MIDDLEWARE` list in `settings.py`, ensuring it is placed after `'django.contrib.auth.middleware.AuthenticationMiddleware'`.
affects: All versions
gotcha`django-otp` is a low-level framework for managing OTPs, not a complete, opinionated two-factor authentication application. While it provides the building blocks, you will need to implement views, forms, and user flows or use a higher-level library like `django-two-factor-auth` for a ready-to-use solution.
fix
Understand `django-otp`'s role as a foundational framework. If you need a complete 2FA application with ready-made UI and flows, consider `django-two-factor-auth`, which builds upon `django-otp`.
affects: All versions
gotchaTo enable QR code generation for HOTP/TOTP devices in the Django admin interface, you must explicitly install either the `qrcode` or `segno` Python package. Without one of these, QR codes will not be displayed.
fix
Install `qrcode` or `segno` using pip: `pip install qrcode` or `pip install segno`.
affects: All versions
Upgrade
Version history
1.7.0latest on PyPI · released Jan 7, 2026
Audit
Dependencies
DjangorequiredCore framework integration for OTP.
qrcodeoptionalOptional: For generating QR codes for HOTP/TOTP devices in the Django admin.
segnooptionalOptional: Alternative to 'qrcode' for generating QR codes for HOTP/TOTP devices in the Django admin (supported since v1.5.0).
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
django-otp — pip install django-otp · libregistry