starsessions
Advanced sessions for Starlette and FastAPI frameworks
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 starsessionsuv
uv add starsessionspoetry
poetry add starsessionsInstalling 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
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
aiohttp-sessionProvides session management for aiohttp.web…
permissive · top 15,000 on PyPI
pyramid-session-redisProvides server-side session storage for…
permissive · top 15,000 on PyPI
starlette-contextMiddleware for Starlette that stores and…
permissive · top 5,000 on PyPI
fastapi-sessionsAdds session authentication to FastAPI…
permissive · top 15,000 on PyPI
starlette-csrfStarlette middleware that protects web…
permissive · top 15,000 on PyPI
starlette-cramjamMiddleware for Starlette that compresses HTTP…
permissive · top 15,000 on PyPI
starlette-compressMiddleware for Starlette and FastAPI that…
permissive · top 5,000 on PyPI
fastapi-lifespan-managerProvides a lifespan manager for FastAPI that…
permissive · top 15,000 on PyPI
starletteStarlette is a lightweight ASGI framework for…
permissive · top 100 on PyPI
django-session-timeoutAdds automatic session expiration to Django…
permissive · top 15,000 on PyPI