skillfed

django-session-timeout

Middleware to expire sessions after specific amount of time

django-session-timeout v0.1.0 77.4K downloads/30d#14,531 on PyPI37
Permissive license MIT Active released

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-timeout

uv

uv add django-session-timeout

poetry

poetry add django-session-timeout

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 2.0Framework :: Django :: 2.1Framework :: Django :: 2.2Framework :: Django :: 3.0License :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7

Tags

django session expirationsession timeout middlewaredjango user session timeoutexpire inactive sessionsdjango session managementsession inactivity timeoutdjango middleware session
django-middlewaresession-managementsecurity

More Dynamic Content packages