The Command Execution Engine is responsible for executing commands in the OpenBB Platform. It handles parameter validation, command invocation, result wrapping in OBBject containers, extension callback triggering, and execution logging. This engine provides a unified execution flow for all user interfaces (Python SDK, CLI, API, Workspace).
For information about how commands are routed to this execution engine, see Architecture. For details on the provider abstraction that the engine delegates to for data fetching, see Provider Architecture.
The execution engine consists of four primary classes that work together to process commands:
| Class | Location | Responsibility |
|---|---|---|
CommandRunner | openbb_core/app/command_runner.py642-723 | Main entry point; manages system/user settings and delegates to StaticCommandRunner |
ExecutionContext | openbb_core/app/command_runner.py34-57 | Container for execution metadata (route, settings, command map) |
ParametersBuilder | openbb_core/app/command_runner.py59-237 | Validates and builds function parameters from args/kwargs |
StaticCommandRunner | openbb_core/app/command_runner.py240-641 | Executes commands, wraps results, triggers callbacks, logs execution |
Sources: openbb_core/app/command_runner.py1-723
The CommandRunner class is instantiated once per session and maintains system and user settings. It provides both async (run) and sync (sync_run) interfaces for command execution.
Sources: openbb_core/app/command_runner.py642-723
ExecutionContext bundles all metadata required for command execution. It includes:
command_map: Maps routes to command functionsroute: The command path (e.g., /equity/price/historical)system_settings: Platform-wide configurationuser_settings: User-specific preferences and credentialsapi_route: FastAPI route metadata (accessed via _route_map)Sources: openbb_core/app/command_runner.py34-57
The execution lifecycle flows through multiple stages, from parameter validation to result wrapping and logging:
The execution process performs these steps:
ExecutionContextOBBject container with results, provider info, warningsSources: openbb_core/app/command_runner.py431-535 openbb_core/app/command_runner.py244-427
The ParametersBuilder class transforms raw function arguments into validated, type-coerced parameters:
Merge Args and Kwargs (openbb_core/app/command_runner.py89-124): Converts positional arguments to keyword arguments based on function signature
Update Command Context (openbb_core/app/command_runner.py127-144): Injects CommandContext if function signature includes cc parameter
Validate and Coerce (openbb_core/app/command_runner.py181-206): Creates a Pydantic model from function signature to validate and type-coerce all parameters
Warn on Unknown Parameters (openbb_core/app/command_runner.py147-168): Emits OpenBBWarning if extra parameters are passed that don't match the function signature
Sources: openbb_core/app/command_runner.py59-237
The validator creates a dynamic Pydantic model to ensure type safety:
This approach automatically converts string "2" to integer 2, validates enums, and ensures required parameters are present.
Sources: openbb_core/app/command_runner.py181-206
All command results are wrapped in an OBBject instance, which provides a standardized output format across all interfaces:
| Field | Type | Description |
|---|---|---|
results | T | None | The actual data returned by the command (list, dict, DataFrame, etc.) |
provider | str | None | Name of the provider that fetched the data (e.g., "fmp", "yfinance") |
warnings | list[Warning_] | Any warnings raised during execution |
chart | Chart | None | Plotly chart object if charting is enabled |
extra | dict | Additional metadata including execution details |
Sources: openbb_core/app/model/obbject.py36-72
OBBject provides multiple methods to convert results into common data formats:
| Method | Return Type | Description |
|---|---|---|
to_dataframe() | DataFrame | Convert results to Pandas DataFrame with optional index/sorting |
to_dict() | dict | list[dict] | Convert to dictionary using Pandas orient options |
to_numpy() | ndarray | Convert to NumPy array |
to_polars() | PolarsDataFrame | Convert to Polars DataFrame |
to_llm() | dict | list[dict] | Convert to LLM-compatible JSON format |
The to_dataframe() method supports multiple input formats including lists of BaseModels, dicts, and nested data structures. It handles complex cases like multiple date columns with timezone awareness.
Sources: openbb_core/app/model/obbject.py81-353
After command execution, the engine triggers registered OBBject extension callbacks. These extensions can add functionality like charting, analytics, or custom transformations:
Extensions are registered in the ExtensionLoader and categorized by route. The callback system:
Loads Callbacks (openbb_core/app/command_runner.py538-543): Retrieves all registered extensions from ExtensionLoader.on_command_output_callbacks
Filters by Route (openbb_core/app/command_runner.py581-591): Executes extensions registered for "*" (all routes) or the specific route
Clones for Immutable Extensions (openbb_core/app/command_runner.py565-576): Creates a copy of OBBject if extension is marked as immutable
Executes Accessor (openbb_core/app/command_runner.py594-621): Calls the extension's accessor function (may be async)
Sets Modification Flags (openbb_core/app/command_runner.py623-628): Updates _extension_modified and _results_only attributes
Sources: openbb_core/app/command_runner.py537-641
| Extension Property | Effect |
|---|---|
immutable=True | Extension runs on a copy; original OBBject unchanged |
immutable=False | Extension modifies the original OBBject; requires allow_mutable_extensions=True |
results_only=True | API returns only the results field instead of full OBBject |
command_output_paths=["route1", "route2"] | Extension only triggers for specified routes |
Sources: openbb_core/app/model/extension.py7-141
The execution engine integrates with the LoggingService to record all command executions:
The logging flow (openbb_core/app/command_runner.py412-425):
CMD: or ERROR: prefixSources: openbb_core/app/logs/logging_service.py199-283
After execution, the engine adds metadata to OBBject.extra["metadata"] (openbb_core/app/command_runner.py458-505):
| Metadata Field | Description |
|---|---|
arguments | All parameters passed to command (standard_params, extra_params, provider_choices) |
duration | Execution time in nanoseconds |
route | Command route path |
timestamp | Execution start time |
The metadata includes cleaned parameters with dependency injections removed to ensure serialization compatibility.
Sources: openbb_core/app/command_runner.py458-534
When chart=True is passed to a command, the engine triggers chart generation via the charting extension:
The chart generation process (openbb_core/app/command_runner.py261-296):
chart_params from extra_params in kwargsOBBjectobbject.charting.show(render=False, **params)obbject.chart fieldSources: openbb_core/app/command_runner.py261-296
The command runner integrates with FastAPI through a wrapper function that handles authentication and response formatting:
The API wrapper (openbb_core/api/router/commands.py212-342):
command_runner.run() with processed parametersJSONResponseSources: openbb_core/api/router/commands.py212-342
The execution engine catches and logs errors while preserving the stack trace:
Error handling occurs at multiple levels:
catch_warnings() context manager to capture warningsOBBject.warningsThe finally block ensures logging always occurs, even if the command raises an exception.
Sources: openbb_core/app/command_runner.py322-427
The complete execution flow through the command runner:
Sources: openbb_core/app/command_runner.py431-535 openbb_core/app/command_runner.py690-710
Refresh this wiki