django-user-sessions
Django sessions with a foreign key to the user
What it is and what it does
Django User Sessions converts Django's built-in session system—which stores all data in opaque base64-encoded blobs—into first-class ORM objects linked to user accounts. This lets you query, filter, and manage sessions like any other Django model. The package stores IP address and user-agent information alongside session data, enabling you to display active sessions to users or administrators and perform bulk operations like logging a user out across all devices.
It's a drop-in replacement for Django's standard session backend, requiring only Django as a runtime dependency. The package supports Django 3.2 and 4.0 on Python 3.7, 3.8, 3.9 and 3.10. Common operations include filtering a user's active sessions by expiration date and deleting all sessions for a user in a single call.
Use it for:
- Display a list of all active sessions for a user in account settings, showing device, IP, and last activity.
- Implement a 'log out everywhere' button that terminates all of a user's sessions at once.
- Query and audit session data for security monitoring or compliance reporting.
- Build admin dashboards that show active user sessions across your application.
- Detect and revoke suspicious sessions based on IP address or user-agent anomalies.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Replaces Django's opaque session backend with queryable ORM objects tied to users, letting you list active sessions, log out users globally, and access IP and user-agent data.
Yes. This is a mature, actively maintained package (Production/Stable status, 719 GitHub stars) that solves a real Django limitation with zero security vulnerabilities and minimal install friction. Use it if you need per-user session visibility or multi-device logout; skip it if you have no need to query or manage sessions programmatically.
Install
django-user-sessions on PyPI
pip
pip install django-user-sessionsuv
uv add django-user-sessionspoetry
poetry add django-user-sessionsInstalling django-user-sessions
Before you install
Low friction: single Django dependency, wheel distribution. Actively maintained with recent commits and no known vulnerabilities.
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-user-sessions
# In Django settings, replace django.contrib.sessions with django_user_sessions
# Then query sessions:
from django.utils.timezone import now
user.session_set.filter(expire_date__gt=now())
# Or logout user everywhere:
user.session_set.all().delete()
Requires Django 3.2 or 4.0; GeoIP setup needed for location detection features.
Verify before relying
- Whether GeoIP setup is required for basic session tracking or only for location detection features.
- Current compatibility with Django versions beyond 4.0 and Python versions beyond 3.10.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — Django |
| Maintenance | actively maintained — 1,340 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 95,197/month — #13,281 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_user_sessions-2.0.0-py3-none-any.whl
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
Flask-LoginFlask-Login handles user session management for…
permissive · top 1,000 on PyPI
django-two-factor-authAdds complete two-factor authentication to…
permissive · top 5,000 on PyPI
django-mock-queriesMocks Django QuerySet operations in memory for…
permissive · top 15,000 on PyPI
django-logentry-adminRegisters Django's built-in LogEntry model in…
permissive · top 15,000 on PyPI
django-netfieldsProvides Django model fields for PostgreSQL…
permissive · top 15,000 on PyPI
quart-authQuart-Auth provides session-based…
permissive · top 15,000 on PyPI
djoserProvides Django REST Framework views for user…
permissive · top 15,000 on PyPI
django-loginasAdds a "Log in as user" button to the Django…
permissive · top 5,000 on PyPI
djongoDjongo translates Django ORM queries into…
permissive · top 15,000 on PyPI