stanza.context

Stanza session management for Stanza CLI.

This module manages the top-level Stanza session (the timestamped directory). This is distinct from LoggerSession which handles per-routine data logging.

Architecture: StanzaSession (this module):

  • Creates timestamped directories like: 20251020100010_untitled/
  • Manages session-level metadata and active session tracking
  • Scope: Global/session-wide, persists across routine runs

LoggerSession (stanza/logger/session.py):

  • Handles per-routine data collection and buffered writing
  • Scope: Per-routine execution, created/destroyed per run

Module Contents

Classes

NameDescription
StanzaSessionManages the active Stanza session directory.

API

1class stanza.context.StanzaSession

Manages the active Stanza session directory.

This class handles the top-level timestamped session directory (e.g., 20251020100010_untitled/) and tracks which session is currently active.

1CONFIG_DIR

Value: .stanza

1CONFIG_FILE

Value: config.json

1create_session_directory(
2 base_path: pathlib.Path | str | None = None, name: str | None = None
3) -> pathlib.Path

Create a new timestamped Stanza session directory.

Parameters:

base_path
pathlib.Path | str | None

Base directory for session (default: current directory)

name
str | None

Optional suffix for directory name (default: “untitled”)

Returns:

Path to created session directory Example:

StanzaSession.create_session_directory() PosixPath(‘20251020100010_untitled’) StanzaSession.create_session_directory(name=“experiment”) PosixPath(‘20251020100010_experiment’)

1get_active_session() -> pathlib.Path | None

Get the active Stanza session directory from working directory config.

Returns:

Path to active session directory, or None if not set Example:

StanzaSession.get_active_session() PosixPath(‘20251020100010_untitled’)

1set_active_session(session_dir: pathlib.Path | str) -> None

Set the active Stanza session directory.

Parameters:

session_dir
pathlib.Path | str

Path to session directory

1get_session_metadata(session_dir: pathlib.Path | str) -> dict[str, typing.Any] | None

Get metadata for a Stanza session directory.

Parameters:

session_dir
pathlib.Path | str

Path to session directory

Returns:

Metadata dictionary or None if not found