hyped.core.features.session module

Module for managing lightweight session-based contextual data.

class hyped.core.features.session.ValidationSession[source]

Bases: object

A lightweight session context manager for managing key-value contextual data.

This class provides a simple way to store, retrieve, and clear context during a specific scope of execution. Contexts are stored as key-value pairs in an internal dictionary, which is cleared automatically when the top-level session ends.

clear_context(key: None | Hashable = None) None[source]

Clear one or all contexts.

Parameters:

key (None | Hashable) – The key of the context entry to clear. If None, all contexts are cleared. Defaults to None.

get_context(key: Hashable) Any[source]

Retrieve the context value associated with a specific key.

Parameters:

key (Hashable) – The key for the context entry to retrieve.

Returns:

The value associated with the key, or None if the key is not found.

Return type:

Any

property session_id: UUID

The unique session ID, generated on demand if not already initialized.

Returns:

A unique identifier for the session.

Return type:

UUID

set_context(key: Hashable, value: Any) None[source]

Set a context value associated with a specific key.

Parameters:
  • key (Hashable) – The key for the context entry.

  • value (Any) – The value to associate with the key.