{"id":21327,"library":"fastapi-sessions","title":"FastAPI Sessions","description":"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.","status":"maintenance","version":"0.3.2","language":"python","source_language":"en","source_url":"https://github.com/jordanisaacs/fastapi-sessions","tags":["fastapi","sessions","authentication","session-management"],"install":[{"cmd":"pip install fastapi-sessions","lang":"bash","label":"default"}],"dependencies":[{"reason":"Required dependency for the library to work.","package":"fastapi","optional":false},{"reason":"For data validation and model definitions.","package":"pydantic","optional":false},{"reason":"For session signing and verification.","package":"itsdangerous","optional":false}],"imports":[{"note":"Wrong path: the main module is fastapi_sessions, not a submodule.","wrong":"from fastapi_sessions.session import SessionManager","symbol":"SessionManager","correct":"from fastapi_sessions import SessionManager"},{"note":"Wrong import: the module is 'backends' (plural), not 'backend'.","wrong":"from fastapi_sessions.backend import SessionBackend","symbol":"SessionBackend","correct":"from fastapi_sessions.backends import SessionBackend"},{"note":"InMemoryBackend is not exported from the backends package directly; import from the submodule.","wrong":"from fastapi_sessions.backends import InMemoryBackend","symbol":"InMemoryBackend","correct":"from fastapi_sessions.backends.in_memory import InMemoryBackend"}],"quickstart":{"code":"from fastapi import FastAPI, HTTPException\nfrom fastapi_sessions import SessionManager\nfrom fastapi_sessions.backends.in_memory import InMemoryBackend\nfrom fastapi_sessions.frontends import SessionFrontend\n\napp = FastAPI()\nbackend = InMemoryBackend()\nfrontend = SessionFrontend(secret_key=\"my-secret-key\")\nmanager = SessionManager(backend=backend, frontend=frontend)\n\n@app.post(\"/login\")\nasync def login(username: str):\n    session_id = await manager.create_session(data={\"user\": username})\n    return {\"session_id\": session_id}\n\n@app.get(\"/me\")\nasync def get_me(session_id: str):\n    session = await manager.get_session(session_id)\n    if not session:\n        raise HTTPException(status_code=401, detail=\"Invalid session\")\n    return session.data","lang":"python","description":"Minimal example: create a session on login, retrieve it on a protected endpoint."},"warnings":[{"fix":"Migrate to Starlette's SessionMiddleware from starlette.middleware.sessions.","message":"Library 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.","severity":"deprecated","affected_versions":">= 0.3.0, < 0.4.0"},{"fix":"Configure a production-ready backend: `from fastapi_sessions.backends.redis import RedisBackend` and provide a Redis connection.","message":"The 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).","severity":"gotcha","affected_versions":"all"},{"fix":"Adjust imports and instantiation to include a frontend and verifier as per the new documentation.","message":"Version 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.","severity":"breaking","affected_versions":"upgrading from <0.3.0 to >=0.3.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `from fastapi_sessions import SessionManager` (not `import fastapi_sessions`).","cause":"Incorrect import path; tried to import from a wrong module.","error":"AttributeError: module 'fastapi_sessions' has no attribute 'SessionManager'"},{"fix":"Use `from fastapi_sessions.backends.in_memory import InMemoryBackend`.","cause":"Trying to import InMemoryBackend from the package's top-level backends module instead of the submodule.","error":"ImportError: cannot import name 'InMemoryBackend' from 'fastapi_sessions.backends'"},{"fix":"Ensure all manager methods (create_session, get_session, etc.) are awaited: e.g., `await manager.create_session(...)`.","cause":"Trying to call session methods without awaiting them.","error":"TypeError: object SessionFrontend can't be used in 'await' expression"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}