Skip to content

jam.aio.sessions.json

json

Classes:

Name Description
JSONSessions

Async session management module for JSON storage.

JSONSessions

JSONSessions(
    json_path: str = "sessions.json",
    is_session_crypt: bool = False,
    session_aes_secret: Optional[bytes] = None,
    id_factory: Callable[[], str] = lambda: str(uuid4()),
)

Bases: JSONSessions

Async session management module for JSON storage.

Dependency required: pip install jamlib[json]

Methods:

Name Description
clear

Clear all sessions for a given session key.

create

Create a new session.

delete

Delete a session by its ID.

get

Retrieve session data by session ID.

rework

Rework (regenerate) a session ID.

update

Update session data by its ID.

clear async

clear(session_key: str) -> None

Clear all sessions for a given session key.

Parameters:

Name Type Description Default
session_key str

The session key to clear.

required

Returns:

Type Description
None

None

create async

create(session_key: str, data: dict) -> str

Create a new session.

Parameters:

Name Type Description Default
session_key str

The session key.

required
data dict

The data to be stored in the session.

required

Returns:

Name Type Description
str str

The ID of the created session.

delete async

delete(session_id: str) -> None

Delete a session by its ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to delete.

required

Returns:

Type Description
None

None

get async

get(session_id) -> Optional[dict]

Retrieve session data by session ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to retrieve.

required

Returns:

Type Description
Optional[dict]

dict | None: The session data if found, otherwise None.

rework async

rework(session_id: str) -> str

Rework (regenerate) a session ID.

Parameters:

Name Type Description Default
session_id str

The current session ID to be reworked.

required

Raises:

Type Description
SessionNotFoundError

If session not found

Returns:

Name Type Description
str str

The new session ID.

update async

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

Update session data by its ID.

Parameters:

Name Type Description Default
session_id str

The ID of the session to update.

required
data dict

The new data to store in the session.

required

Returns:

Type Description
None

None

FILE PATH: jam/aio/sessions/json.py