Api Module API Reference¶
This section documents the internals of the api
module in Bijux CLI.
bijux_cli.api ¶
Provides a high-level, synchronous facade for the Bijux CLI's core engine.
This module defines the BijuxAPI
class, which serves as the primary public interface for programmatic interaction with the CLI. It wraps the asynchronous core Engine
and other services to present a stable, thread-safe, and synchronous API.
This facade is intended for use in integrations, testing, or any scenario where the CLI's command and plugin management logic needs to be embedded within another Python application.
BijuxAPI ¶
A thread-safe, synchronous access layer for the Bijux CLI engine.
This class provides a stable public API for registering commands, executing them, and managing plugins. It wraps the internal asynchronous Engine
to allow for simpler, synchronous integration into other applications.
Attributes:
-
_di
(DIContainer
) –The dependency injection container.
-
_engine
(Engine
) –The core asynchronous runtime engine.
-
_registry
(RegistryProtocol
) –The plugin registry service.
-
_obs
(ObservabilityProtocol
) –The logging service.
-
_tel
(TelemetryProtocol
) –The telemetry service.
Initializes the BijuxAPI
and the underlying CLI engine.
Parameters:
-
debug
(bool
, default:False
) –If True, enables debug mode for all underlying services. Defaults to False.
Source code in src/bijux_cli/api.py
load_plugin ¶
Loads or reloads a plugin module from a file path.
This method dynamically loads the specified plugin file, initializes it, and registers it with the CLI system. If the plugin is already loaded, it is reloaded.
Parameters:
-
path
(str | Path
) –The filesystem path to the plugin's Python file.
Raises:
-
BijuxError
–If plugin loading, initialization, or registration fails.
Source code in src/bijux_cli/api.py
register ¶
Registers or replaces a Python callable as a CLI command.
The provided callable is wrapped to handle both synchronous and asynchronous functions automatically.
Parameters:
-
name
(str
) –The command name to register.
-
callback
(Callable[..., Any]
) –The Python function to be executed when the command is run.
Raises:
-
BijuxError
–If the command name is already in use or another registration error occurs.
Source code in src/bijux_cli/api.py
run_async async
¶
run_async(
name: str,
*args: Any,
quiet: bool = False,
verbose: bool = False,
fmt: str = "json",
pretty: bool = True,
debug: bool = False,
**kwargs: Any,
) -> Any
Runs a command asynchronously with validation.
This method performs validation of flags and environment variables before dispatching the command to the internal engine for execution.
Parameters:
-
name
(str
) –The name of the command to execute.
-
*args
(Any
, default:()
) –Positional arguments for the command.
-
quiet
(bool
, default:False
) –If True, suppresses output.
-
verbose
(bool
, default:False
) –If True, enables verbose output.
-
fmt
(str
, default:'json'
) –The output format ("json" or "yaml").
-
pretty
(bool
, default:True
) –If True, formats the output for readability.
-
debug
(bool
, default:False
) –If True, enables debug mode.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments to pass to the command.
Returns:
-
Any
(Any
) –The result of the command's execution.
Raises:
-
BijuxError
–For invalid flags, unsupported formats, or internal execution errors.
Source code in src/bijux_cli/api.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
run_sync ¶
run_sync(
name: str,
*args: Any,
quiet: bool = False,
verbose: bool = False,
fmt: str = "json",
pretty: bool = True,
debug: bool = False,
**kwargs: Any,
) -> Any
Runs a command synchronously.
This method is a blocking wrapper around the asynchronous run_async
method. It manages the asyncio event loop to provide a simple, synchronous interface.
Parameters:
-
name
(str
) –The name of the command to run.
-
*args
(Any
, default:()
) –Positional arguments for the command.
-
quiet
(bool
, default:False
) –If True, suppresses output.
-
verbose
(bool
, default:False
) –If True, enables verbose logging.
-
fmt
(str
, default:'json'
) –The output format ("json" or "yaml").
-
pretty
(bool
, default:True
) –If True, formats the output for readability.
-
debug
(bool
, default:False
) –If True, enables debug mode.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments to pass to the command.
Returns:
-
Any
(Any
) –The result of the command's execution.