App Context
Application context for managing configuration, authentication, and HTTP clients.
Application context and dependency injection.
AppContext is a framework-agnostic dependency injection container that works
with CLI, web applications, and programmatic usage. It provides access to
config, auth, logging, and runtime configuration.
Typical usage::
from qlam_core.common.context import AppContext
# Basic usage
ctx = AppContext(context_name="dev", verbose=True)
print(ctx.config.context_name)
# Web application usage
web_ctx = AppContext(
context_name=f"user_{user_id}",
output_format="json",
verbose=False
)
# Usage with display options
cli_ctx = AppContext(
context_name="production",
output_format="table",
wrap=True
)
AppContext
AppContext(context_name: str | None = None, output_format: str | None = None, verbose: bool = False, wrap: bool = False, logger: Logger | None = None, cached_config: 'Config' | None = None, visibility: Visibility | None = None, default_headers: Mapping[str, str] | None = None)
Framework-agnostic dependency injection container.
This class provides access to config, authentication, and logging for any application interface (CLI, web, programmatic).
:param context_name: Optional context name override for user/session isolation.
:param output_format: Output format preference ("table" or "json").
:param verbose: Enable verbose logging.
:param wrap: Allow multiline wrapping in table output (display hint).
:param logger: Logger instance to use; defaults to module logger.
:param cached_config: Inject config (avoids reloading from disk).
:param visibility: API visibility mode override (None defers to config resolution).
:param default_headers: Default HTTP headers to apply to SDK-created clients.
Stored as a read-only mapping after construction.
Source code in qlam_core/common/context.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
effective_output_format
property
effective_output_format: str
Get the effective output format, considering TTY detection.
This property provides smart defaults for output formatting based on the execution environment. Useful for CLI but can be overridden for web/programmatic usage.
:return: "table" for TTY environments, "json" otherwise, unless explicitly set.
qpu
property
qpu: str
Get the QPU from config.
:return: Currently configured QPU identifier.
credentials_view
credentials_view(redacted: bool = True) -> list[dict]
Get a read-only view of cached credentials across all providers.
:param redacted: If True, hide sensitive fields. :return: List of cache metadata dicts.
Source code in qlam_core/common/context.py
142 143 144 145 146 147 148 | |