Skip to content

API Reference

This section contains the complete API documentation for the Dashboard Compiler.

Overview

The Dashboard Compiler provides a Python API for creating Kibana dashboards programmatically. For a high-level guide on programmatic usage, see the Programmatic Usage Guide.

Core Modules

  • Dashboard – Dashboard configuration and compilation
  • Panels – Panel types and compilation logic (includes Python examples)
  • Controls – Control group configuration
  • Filters – Filter compilation
  • Queries – Query compilation

Core Functions

The Dashboard Compiler provides these core functions for working with dashboards:

dashboard_compiler

Provides functions to load, render, and dump YAML-to-Lens Dashboards.

load

load(path, allow_deprecated=False)

Load dashboard configurations from a YAML file.

Parameters:

Name Type Description Default
path str

The path to the YAML file containing the dashboard configuration.

required
allow_deprecated bool

Deprecated flag retained for API compatibility (no-op in 0.4.0+).

False

Returns:

Type Description
list[Dashboard]

list[Dashboard]: The loaded Dashboard objects.

Source code in kb_dashboard_core/dashboard_compiler.py
@log_compile
def load(path: str, allow_deprecated: bool = False) -> list[Dashboard]:
    """Load dashboard configurations from a YAML file.

    Args:
        path (str): The path to the YAML file containing the dashboard configuration.
        allow_deprecated (bool): Deprecated flag retained for API compatibility (no-op in 0.4.0+).

    Returns:
        list[Dashboard]: The loaded Dashboard objects.

    """
    load_path = Path(path)
    _ = allow_deprecated

    with load_path.open(encoding='utf-8') as file:
        config_data = yaml.safe_load(file)  # pyright: ignore[reportAny]

    config = DashboardConfig.model_validate(config_data)

    for dashboard in config.dashboards:
        logger.info('Loaded dashboard: %s', dashboard.name)

    return config.dashboards

render

render(dashboard)

Render a Dashboard object into its Kibana JSON representation.

Parameters:

Name Type Description Default
dashboard Dashboard

The Dashboard object to render.

required

Returns:

Name Type Description
KbnDashboard KbnDashboard

The rendered Kibana dashboard view model.

Source code in kb_dashboard_core/dashboard_compiler.py
@log_compile
def render(dashboard: Dashboard) -> KbnDashboard:
    """Render a Dashboard object into its Kibana JSON representation.

    Args:
        dashboard (Dashboard): The Dashboard object to render.

    Returns:
        KbnDashboard: The rendered Kibana dashboard view model.

    """
    return compile_dashboard(dashboard)

dump

dump(dashboards, path)

Dump Dashboard objects to a YAML file.

Parameters:

Name Type Description Default
dashboards list[Dashboard]

The Dashboard objects to dump.

required
path str

The path where the YAML file will be saved.

required
Source code in kb_dashboard_core/dashboard_compiler.py
@log_compile
def dump(dashboards: list[Dashboard], path: str) -> None:
    """Dump Dashboard objects to a YAML file.

    Args:
        dashboards (list[Dashboard]): The Dashboard objects to dump.
        path (str): The path where the YAML file will be saved.

    """
    dashboard_path = Path(path)

    with dashboard_path.open(mode='w', encoding='utf-8') as file:
        dashboards_as_list = [dashboard.model_dump(serialize_as_any=True, exclude_none=True) for dashboard in dashboards]
        config = {'dashboards': dashboards_as_list}
        yaml.dump(config, file, default_flow_style=False, sort_keys=False)