skillfed

starsessions

Advanced sessions for Starlette and FastAPI frameworks

starsessions v2.2.1 449.2K downloads/30d#6,597 on PyPI123
Permissive license MIT Active released

What it is and what it does

Starsessions is a session middleware library for Starlette and FastAPI that manages user session data across HTTP requests. It abstracts session storage behind a pluggable backend system, offering three built-in stores: CookieStore (client-side signed cookies), InMemoryStore (for testing), and RedisStore (for distributed deployments). The middleware handles cookie lifecycle, security defaults (HTTPS-only, browser-session lifetime by default), and optional autoloading to reduce boilerplate.

The library is designed for developers building async web applications who need flexible session handling without reinventing session management. It supports rolling sessions (where inactivity resets the timeout), path and domain binding for cookies, and explicit session loading to avoid performance overhead. Dependencies are minimal (starlette and itsdangerous), and the package supports Python 3.8 through 3.13.

Use it for:

  • Add session support to a FastAPI REST API with cookie-based authentication and 14-day rolling expiration
  • Store user preferences and shopping cart data in Redis for a multi-instance web application
  • Implement admin-only session cookies scoped to /admin paths with automatic cleanup on browser close
  • Unit test session behavior using InMemoryStore without external dependencies
  • Migrate from stateless JWT to session-based auth with automatic session extension on user activity

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides session management middleware for Starlette and FastAPI applications, supporting multiple storage backends including cookies, in-memory storage, and Redis with configurable expiration strategies.

Yes. Starsessions is production-ready (Development Status 5), actively maintained, has zero known vulnerabilities, and solves a common problem in Starlette/FastAPI applications with minimal dependencies and flexible storage options. The permissive MIT license and broad Python version support (3.8–3.13) make it suitable for most projects.

Install

starsessions on PyPI

pip

pip install starsessions

uv

uv add starsessions

poetry

poetry add starsessions

Installing starsessions

Before you install

Low install friction with only two runtime dependencies (starlette and itsdangerous). The package is actively maintained with a recent commit on 2026-03-16 and has been in production use since 2021-06-24.

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal obligations—suitable for both open-source and commercial projects.

Quickstart

pip install starsessions

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starsessions import CookieStore, SessionMiddleware, load_session

session_store = CookieStore(secret_key='TOP SECRET')
app = Starlette(
    middleware=[Middleware(SessionMiddleware, store=session_store, lifetime=3600 * 24 * 14)]
)

async def view(request):
    await load_session(request)
    request.session['key'] = 'value'

Verify before relying

  • Whether Redis extra installation (starsessions[redis]) is required for production deployments or optional for development
  • Performance characteristics when handling high-concurrency session loads across different storage backends

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0.0,>=3.8.0)
Install friction low — pure-Python wheel
Runtime dependencies 2 — starlette, itsdangerous
Maintenance actively maintained — 660 days since the last release
Last repo commit
First released
Downloads 449,233/month — #6,597 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: starsessions-2.2.1-py3-none-any.whl

Keywords: starlette, fastapi, asgi, session

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTyping :: Typed

Tags

starlette session middlewarefastapi session managementasgi session storecookie-based sessionsredis session storagerolling sessionssession autoload middleware
session-managementasgi-middlewarestarlette-fastapi

More Libraries packages