Skip to main content

SessionProtocol

Protocol for session storage backends.

Implementations can use Redis, database, or other storage.

Methods:
create: Create a new session
get: Retrieve session by ID
delete: Delete a session
delete_all_for_user: Delete all sessions for a user
list_for_user: List all sessions for a user

Source: session.py

Methods

create

async def create(self,
user_id: str,
ip_address: str | None = None,
user_agent: str | None = None,
) -> SessionData

Create a new session.

    Args:
user_id: User ID to create session for
ip_address: Optional client IP
user_agent: Optional client user agent

Returns:
Created SessionData with session_id

get

async def get(self, session_id: str) -> SessionData | None

Get session by ID.

    Args:
session_id: Session identifier

Returns:
SessionData if found and not expired, None otherwise

delete

async def delete(self, session_id: str) -> bool

Delete a session.

    Args:
session_id: Session to delete

Returns:
True if deleted, False if not found

delete_all_for_user

async def delete_all_for_user(self, user_id: str) -> int

Delete all sessions for a user.

    Args:
user_id: User whose sessions to delete

Returns:
Number of sessions deleted

list_for_user

async def list_for_user(self, user_id: str) -> list[SessionData]

List all active sessions for a user.

    Args:
user_id: User to list sessions for

Returns:
List of active SessionData