django-session-timeout
Middleware to expire sessions after specific amount of time
What it is and what it does
django-session-timeout is a Django middleware that enforces automatic session expiration based on time. It adds timestamp tracking to sessions and can expire them either after a fixed duration from session creation or after a period of user inactivity. The middleware integrates into Django's standard session framework and requires minimal configuration—just adding it to MIDDLEWARE_CLASSES and setting SESSION_EXPIRE_SECONDS.
The package supports flexible expiration strategies: you can track inactivity with optional grace-period grouping to reduce database writes, and redirect expired sessions to a custom URL. It depends on Django and six, making it lightweight and compatible with existing Django projects.
Use it for:
- Enforce security policies requiring user sessions to expire after a fixed time period in web applications.
- Log out inactive users automatically to reduce unauthorized access risk in shared or public-facing systems.
- Implement inactivity-based timeouts that reset on user activity to balance security with user experience.
- Redirect expired sessions to a login page or custom endpoint for graceful session termination.
- Group activity timestamps by different periods to reduce database load while tracking user inactivity.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds automatic session expiration to Django applications, allowing sessions to expire after a fixed duration or period of inactivity.
Yes. The package is stable, actively maintained, has low install friction, carries no known vulnerabilities, and solves a common Django security need. MIT licensing imposes no restrictions. Install it if you need automatic session expiration; the configuration is straightforward and the middleware integrates cleanly into Django's standard session handling.
Install
django-session-timeout on PyPI
pip
pip install django-session-timeoutuv
uv add django-session-timeoutpoetry
poetry add django-session-timeoutInstalling django-session-timeout
Before you install
Low friction installation with only 2 runtime dependencies. Actively maintained with recent commits; last update was 2026-04-28. Stable production release status.
License in practice
MIT license is permissive, allowing commercial and private use with minimal restrictions.
Quickstart
pip install django-session-timeout
# In settings.py, add to MIDDLEWARE_CLASSES:
'django_session_timeout.middleware.SessionTimeoutMiddleware',
# Set expiration time:
SESSION_EXPIRE_SECONDS = 3600
Requires Django and six as runtime dependencies; must be added to Django's MIDDLEWARE_CLASSES configuration.
Verify before relying
- Whether the package supports Django versions released after 3.0 (classifiers list only through 3.0)
- Whether Python 3.8+ is supported (classifiers only list through 3.7)
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — Django, six |
| Maintenance | actively maintained — 2,350 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 77,369/month — #14,531 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_session_timeout-0.1.0-py2.py3-none-any.whl
Tags
More Dynamic Content packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
soupsieveSoupsieve is a CSS selector library designed to…
permissive · top 100 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
FlaskFlask is a lightweight WSGI web application…
permissive · top 1,000 on PyPI
MakoMako compiles Python-embedded templates into…
permissive · top 1,000 on PyPI
expiring-dictExpiringDict is a Python dictionary that…
permissive · top 15,000 on PyPI
starsessionsProvides session management middleware for…
permissive · top 15,000 on PyPI
django-crumDjango-CRUM stores the current request and user…
permissive · top 15,000 on PyPI
django-defenderBlocks brute-force login attempts in Django by…
permissive · top 15,000 on PyPI
expiringdictExpiringDict is an ordered dictionary that…
permissive · top 5,000 on PyPI
django-cprofile-middlewareMiddleware that profiles Django view execution…
permissive · top 15,000 on PyPI
django-pgactivityProvides Django management commands and…
permissive · top 5,000 on PyPI
django-htmlminMinifies HTML by removing whitespace and…
permissive · top 5,000 on PyPI
aiohttp-sessionProvides session management for aiohttp.web…
permissive · top 15,000 on PyPI