Install & Compatibility
Where this runs
tested against v0.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 32.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 0.000s · 32MB
30MB installed
● package 30MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SessionManager
✓ from fastapi_sessions import SessionManager
✗ from fastapi_sessions import SessionManager
Minimal example: create a session on login, retrieve it on a protected endpoint.
from fastapi import FastAPI, HTTPException
from fastapi_sessions import SessionManager
from fastapi_sessions.backends.in_memory import InMemoryBackend
from fastapi_sessions.frontends import SessionFrontend
app = FastAPI()
backend = InMemoryBackend()
frontend = SessionFrontend(secret_key="my-secret-key")
manager = SessionManager(backend=backend, frontend=frontend)
@app.post("/login")
async def login(username: str):
session_id = await manager.create_session(data={"user": username})
return {"session_id": session_id}
@app.get("/me")
async def get_me(session_id: str):
session = await manager.get_session(session_id)
if not session:
raise HTTPException(status_code=401, detail="Invalid session")
return session.data
Debug
Known issues
deprecatedLibrary is in maintenance mode; no active development or bug fixes are expected. Consider alternatives like session-based auth with Starlette's built-in session middleware.fixMigrate to Starlette's SessionMiddleware from starlette.middleware.sessions.
affects: >= 0.3.0, < 0.4.0
gotchaThe default in-memory backend is not suitable for production; sessions are lost on server restart. Use a persistent backend like RedisBackend (from fastapi_sessions.backends.redis).fixConfigure a production-ready backend: `from fastapi_sessions.backends.redis import RedisBackend` and provide a Redis connection.
affects: all
breakingVersion 0.3.0 introduced a breaking rewrite: the API changed from a single SessionManager to customizable Frontend and Verifier components. Older code using SessionManager directly without frontends will break.fixAdjust imports and instantiation to include a frontend and verifier as per the new documentation.
affects: upgrading from <0.3.0 to >=0.3.0
Upgrade
Version history
0.3.2latest on PyPI · released Sep 11, 2021
Audit
Dependencies
fastapirequiredRequired dependency for the library to work.
pydanticrequiredFor data validation and model definitions.
itsdangerousrequiredFor session signing and verification.