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).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_name
|
str | None
|
Optional context name override for user/session isolation. |
None
|
output_format
|
str | None
|
Output format preference ("table" or "json"). |
None
|
verbose
|
bool
|
Enable verbose logging. |
False
|
wrap
|
bool
|
Allow multiline wrapping in table output (display hint). |
False
|
logger
|
Logger | None
|
Logger instance to use; defaults to module logger. |
None
|
cached_config
|
'Config' | None
|
Inject config (avoids reloading from disk). |
None
|
visibility
|
Visibility | None
|
API visibility mode override ( |
None
|
default_headers
|
Mapping[str, str] | None
|
Default HTTP headers to apply to SDK-created clients. Stored as a read-only mapping after construction. |
None
|
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.
Returns:
| Type | Description |
|---|---|
str
|
"table" for TTY environments, "json" otherwise, unless explicitly set. |
qpu
property
qpu: str
Get the QPU from config.
Returns:
| Type | Description |
|---|---|
str
|
Currently configured QPU identifier. |
credentials_view
credentials_view(redacted: bool = True) -> list[dict]
Get a read-only view of cached credentials across all providers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
redacted
|
bool
|
If True, hide sensitive fields. |
True
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of cache metadata dicts. |
Source code in qlam_core/common/context.py
142 143 144 145 146 147 148 | |