Skip to content

jam.aio.sessions.base

__base__

Classes:

Name Description
BaseAsyncSessionModule

Abstract base class for async session management modules.

BaseAsyncSessionModule

BaseAsyncSessionModule(
    id_factory: Callable[[], str] = lambda: str(uuid4()),
    is_session_crypt: bool = False,
    session_aes_secret: bytes | str | None = None,
    serializer: type[BaseEncoder]
    | BaseEncoder = JsonEncoder,
    logger: BaseLogger | None = None,
)

Bases: ABC

Abstract base class for async session management modules.

Methods:

Name Description
__decode_session_data__

Decode session data.

__decode_session_id__

Decode the session using AES decryption.

__decode_session_id_if_needed__

Decode the session ID if it is encoded.

__encode_session_data__

Encode session data.

__encode_session_id__

Encode the session using AES encryption.

__encode_session_id_if_needed__

Encode the session ID if it is not already encoded.

clear

Clear all sessions by key.

create

Create a new session with the given session key and data.

delete

Delete a session by its key or ID.

get

Retrieve a session by its key or ID.

rework

Rework a session and return its new ID.

update

Update an existing session with new data.

Attributes:

Name Type Description
id str

Return the unique ID use id_factory.

id property

id: str

Return the unique ID use id_factory.

__decode_session_data__

__decode_session_data__(data: str) -> dict

Decode session data.

__decode_session_id__

__decode_session_id__(data: str) -> str

Decode the session using AES decryption.

__decode_session_id_if_needed__

__decode_session_id_if_needed__(data: str) -> str

Decode the session ID if it is encoded.

__encode_session_data__

__encode_session_data__(data: dict) -> str

Encode session data.

__encode_session_id__

__encode_session_id__(data: str) -> str

Encode the session using AES encryption.

__encode_session_id_if_needed__

__encode_session_id_if_needed__(data: str) -> str

Encode the session ID if it is not already encoded.

clear abstractmethod async

clear(session_key: str) -> None

Clear all sessions by key.

Parameters:

Name Type Description Default
session_key str

The key for the sessions to clear.

required

create abstractmethod async

create(session_key: str, data: dict[str, Any]) -> str

Create a new session with the given session key and data.

Parameters:

Name Type Description Default
session_key str

The key for the session.

required
data dict[str, Any]

The data to be stored in the session.

required

Returns:

Name Type Description
str str

The session ID.

delete abstractmethod async

delete(session_id: str) -> None

Delete a session by its key or ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session.

required

get abstractmethod async

get(session_id: str) -> dict[str, Any] | None

Retrieve a session by its key or ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session.

required

Returns:

Type Description
dict[str, Any] | None

dict[str, Any] | None: The session data if found, otherwise None.

rework abstractmethod async

rework(session_id: str) -> str

Rework a session and return its new ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to rework.

required

Raises:

Type Description
JamSessionNotFound

If the session with the given ID does not exist.

Returns:

Name Type Description
str str

The new session ID.

update abstractmethod async

update(session_id: str, data: dict[str, Any]) -> None

Update an existing session with new data.

Parameters:

Name Type Description Default
session_id str

The ID of the session to update.

required
data dict[str, Any]

The new data to be stored in the session.

required

Raises:

Type Description
JamSessionNotFound

If the session with the given ID does not exist.