Registry / web-framework / fastapi-sessions

fastapi-sessions

JSON →
library0.3.2pypypiunverified

A ready-to-use session library for FastAPI, providing customizable frontends, verifiers, and backends. Current version 0.3.2, released 2023 as maintenance mode; no active development.

pip install fastapi-sessions
INSTALL
IMPORT
SIG · FASTAPI-SESSIONS
F
fastapi-sessions
web-frameworkpythonv0.3.2
Install
3.8s avg
Import
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 32.1MB
glibc
py 3.103.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.
fix
Migrate 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).
fix
Configure 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.
fix
Adjust 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.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
fastapi-sessions — pip install fastapi-sessions · libregistry