Skip to content

comet_ml.views

comet_ml.views -- a builder library for Comet views.

Views are the saved project and per-experiment layouts in the Comet UI. This module builds them programmatically: import the panel factories, compose them into Section objects, and hand the result to build_view() (project views) or build_experiment_view() (per-experiment views).

from comet_ml.views import Section, build_view, line_panel, scalar_panel

view = build_view(
    "My View",
    sections=[
        Section("At a glance", [scalar_panel("accuracy", aggregation="max")]),
        Section("Curves", [line_panel(["loss", "val_loss"], smoothing=0.6)]),
    ],
)
comet_ml.API().create_view(workspace, project_name, view)

The Comet SDK exposes these functions for working with saved views:

API.get_views(workspace, project_name)      -> list[View]
API.create_view(workspace, project_name, v) -> View     (project-level)
API.update_view(workspace, project_name, v) -> View     (in place)
APIExperiment.get_views()                   -> list[View]
APIExperiment.create_view(view)             -> View     (experiment-level)
APIExperiment.update_view(view)             -> View     (in place)

A View is mostly a carrier for the view's serialized layout state, and the interesting content lives in view.v3 -- a dict of sections, each holding panels plus a grid layout. This module provides typed-ish factories for every panel type the view supports, plus build_view() to assemble sections into a View that the Comet UI renders correctly.

Schema notes (derived from views saved by the Comet UI):

v3 = { "layout": [], # legacy mirror of section[0]; safe to leave empty "globalConfig": {...}, # view-wide x-axis / smoothing / sampling "sections": [ {"id": "aB3xY9", "title": "Metrics", "autogenerated": False, "expanded": True, "panels": [ ... ], "layout": [ ... ]}, ], "autoGenerate": False, # True lets Comet append auto panels for new metrics "isPersonalView": False, }

chart_state ("dashboardChartState") is the pre-sections legacy format: the same panel dicts bucketed by type. We emit it alongside v3 for compatibility with older backends and with code that reads the legacy field.

query_state ("experimentQueryState") holds the filter/segment state. table_state ("reactGridTableState") holds the experiment table config.

Experiment-level views (the chart-template scope, written by APIExperiment.create_view) use a different envelope: the sections live in view.v2["panels"] and the display settings sit at the top of v2, with v3 unused. build_view targets the project scope and build_experiment_view the experiment scope; sections and panels are identical between the two. create_view and update_view raise ValueError when given the other scope's envelope, which the backend would otherwise save but render with no panels.

Nothing here calls the network; build_view returns a plain View that you pass to API.create_view, and build_experiment_view one for APIExperiment.create_view.

Section

Section(
    title: str,
    panels: Sequence[Dict[str, Any]] = (),
    columns: int = 3,
    expanded: bool = True,
    height: int = 1,
)

A titled, collapsible group of panels on a view.

Parameters:

  • title (str) –

    the section header shown in the UI.

  • panels (Sequence[Dict[str, Any]], default: () ) –

    panel dicts from the factories above.

  • columns (int, default: 3 ) –

    panels per row (1, 2, or 3). Panels flow left to right.

  • expanded (bool, default: True ) –

    whether the section starts open.

  • height (int, default: 1 ) –

    row height in grid units (1 is the UI default, max 3).

columns instance-attribute

columns = columns

expanded instance-attribute

expanded = expanded

height instance-attribute

height = height

id instance-attribute

id = new_id()

panels instance-attribute

panels = list(panels)

title instance-attribute

title = title

add

add(*panels: Dict[str, Any]) -> Section

Append panels; returns self so calls can be chained.

layout

layout() -> List[Dict[str, Any]]

Compute the react-grid-layout entries for this section's panels.

to_dict

to_dict() -> Dict[str, Any]

all_of

all_of(*rules: Dict[str, Any]) -> Dict[str, Any]

AND-group of rules; use as one branch inside query_state.

any_of

any_of(*groups: Dict[str, Any]) -> Dict[str, Any]

OR of AND-groups -- the shape the filter builder produces.

bar_panel

bar_panel(
    metric: str,
    name: str = "",
    aggregation: Aggregation = "last",
    orientation: Orientation = "v",
    plot_type: PlotType = "bar",
    group_by_aggregation: Optional[GroupAggregation] = None,
    legend: Optional[List[Dict[str, Any]]] = None,
    group_by: Optional[str] = None,
) -> Dict[str, Any]

A bar chart of one metric, one bar per experiment.

Parameters:

  • aggregation (Aggregation, default: 'last' ) –

    how to reduce a metric's history to one number -- "last", "first", "min", "max", "average", "median", "sum", ...

  • orientation (Orientation, default: 'v' ) –

    "v" (vertical bars) or "h".

  • plot_type (PlotType, default: 'bar' ) –

    "bar", "stacked_bar", "box", or "violin".

  • group_by_aggregation (Optional[GroupAggregation], default: None ) –

    "mean", "median", "min" or "max"; with group_by, how each group's bar is computed.

  • group_by (Optional[str], default: None ) –

    a hyperparameter name; experiments sharing its value are drawn as one group (one box, for a box plot).

build_experiment_view

build_experiment_view(
    name: str,
    sections: Sequence[Section],
    config: Optional[Dict[str, Any]] = None,
    auto_generate: bool = False,
    auto_refresh: bool = True,
    media_sort_by: str = "name",
    media_order: str = "desc",
    group_media: bool = False,
) -> View

Assemble sections into a View for APIExperiment.create_view.

Experiment-scoped views are stored in the chart-template tables, which use a different envelope than project views: everything lives under v2 (sections inside v2["panels"]), and the per-tab display settings for images / text / audio / histograms / confusion matrices sit alongside them.

Parameters:

  • name (str) –

    the view's display name.

  • sections (Sequence[Section]) –

    Section objects -- the same ones build_view takes.

  • config (Optional[Dict[str, Any]], default: None ) –

    output of global_config(), as for build_view: the x-axis, smoothing, y transform, outliers and sample size applied to every chart.

  • auto_generate (bool, default: False ) –

    let Comet append auto panels for new metrics.

  • auto_refresh (bool, default: True ) –

    refresh the view while the run is live.

  • media_sort_by (/ media_order / group_media, default: 'name' ) –

    sorting of the image, audio and text tabs.

Returns:

  • View –

    A View to pass to APIExperiment.create_view(view). Do not set

  • View –

    experiment_key -- create_view stamps it on for you.

build_view

build_view(
    name: str,
    sections: Sequence[Section],
    filters: Optional[str] = None,
    table: Optional[str] = None,
    config: Optional[Dict[str, Any]] = None,
    auto_generate: bool = False,
    personal: bool = False,
) -> View

Assemble sections into a View ready for create_view.

Parameters:

  • name (str) –

    the view's display name.

  • sections (Sequence[Section]) –

    Section objects, top to bottom.

  • filters (Optional[str], default: None ) –

    output of query_state(), or None for no filtering.

  • table (Optional[str], default: None ) –

    output of table_state(), or None to keep the UI default.

  • config (Optional[Dict[str, Any]], default: None ) –

    output of global_config().

  • auto_generate (bool, default: False ) –

    True lets Comet append auto-generated panels for newly logged metrics underneath your sections.

  • personal (bool, default: False ) –

    mark the view as personal (visible only to you).

Returns:

  • View –

    A View for a project view. Pass it to

  • View –

    API.create_view(workspace, project, view); for an experiment's own

  • View –

    page, build with build_experiment_view instead.

custom_panel

custom_panel(
    instance_id: str,
    instance_name: str = "",
    name: str = "",
    default_config: str = "",
) -> Dict[str, Any]

An instance of a JavaScript panel saved in the Panel library.

instance_id/instance_name identify an existing panel instance and cannot be invented -- copy them off a panel already on a view (scan existing views with get_views()) or from the panel's URL in the UI. To write a JavaScript panel from nothing, use javascript_panel.

data_panel

data_panel(
    file_name: str,
    name: str = "",
    axis: int = 0,
    join_type: str = "outer",
    experiments_count: int = 25,
) -> Dict[str, Any]

A table panel rendering a logged tabular asset (e.g. a .csv).

Parameters:

  • file_name (str) –

    the logged asset's file name, as passed to log_table().

  • axis (int, default: 0 ) –

    0 concatenates rows across experiments, 1 concatenates columns.

  • join_type (str, default: 'outer' ) –

    "outer" or "inner", when combining across experiments.

describe_view

describe_view(view: View, indent: str = '') -> str

Render a human-readable outline of a View's sections and panels.

global_config

global_config(
    x_axis: str = "step",
    smoothing: float = 0,
    transform_y: Optional[TransformY] = None,
    outliers: Outliers = "show",
    sample_size: int = 100,
) -> Dict[str, Any]

View-wide defaults applied to every non-locked panel.

Pass the result as config to build_view or build_experiment_view; one value can be built once and passed to both. transform_y and outliers take the same values as in line_panel.

image_panel

image_panel(
    images: Sequence[str] = (),
    step: Optional[int] = None,
    name: str = "",
    experiments_count: int = 25,
) -> Dict[str, Any]

An image-grid panel showing logged images across experiments.

Parameters:

  • images (Sequence[str], default: () ) –

    logged image file names to display. Empty means "all".

  • step (Optional[int], default: None ) –

    pin the grid to one step; None follows the view.

javascript_panel

javascript_panel(
    code: str,
    html: str = JS_PANEL_DEFAULT_HTML,
    css: str = "",
    resources: Sequence[Union[str, Dict[str, str]]] = (),
    name: str = "",
) -> Dict[str, Any]

A JavaScript panel whose code is stored in the view itself.

Unlike custom_panel, this needs no existing panel: the code, HTML, CSS and resources are all saved in the panel's config, so it can be written from nothing. The code defines a Comet.Panel subclass, which must be named MyPanel; the panel runs nothing else:

class MyPanel extends Comet.Panel {
  setup() { this.options = {metrics: ["loss"]}; }
  async draw(experimentKeys, projectId) {
    const results = await this.api.experimentMetricsForChart(
      experimentKeys, this.options.metrics);
    this.plot({data: [...], layout: {}});
  }
}

this.plot({data, layout}) hands a Plotly figure to the page, which draws it like its built-in charts; only the scatter, bar, box, violin and parcoords trace types are available. A panel that never calls this.plot shows its own HTML instead.

Parameters:

  • code (str) –

    the panel's JavaScript.

  • html (str, default: JS_PANEL_DEFAULT_HTML ) –

    the panel's HTML. The default holds the element charts draw into.

  • css (str, default: '' ) –

    the panel's stylesheet.

  • resources (Sequence[Union[str, Dict[str, str]]], default: () ) –

    extra scripts and stylesheets, loaded in order before the code runs. Each is a URL, or a dict {"url": ..., "type": ...} with type "script" or "stylesheet". A bare URL is a stylesheet if it ends in .css, and a script otherwise.

  • name (str, default: '' ) –

    the panel's title.

legend_key

legend_key(
    value: str = "Name", label: Optional[str] = None, source: str = "log_other"
) -> Dict[str, Any]

One entry of a chart's selectedLegendKeys.

Common combinations

legend_key("Name") # experiment name legend_key("experimentTags", "Tags", "tags") # tags legend_key("learning_rate", source="params") # a hyperparameter

line_panel

line_panel(
    metric: Union[str, Sequence[str]],
    x: str = "step",
    name: str = "",
    smoothing: float = 0,
    transform_y: Optional[TransformY] = None,
    outliers: Outliers = "show",
    sample_size: int = 100,
    legend: Optional[List[Dict[str, Any]]] = None,
    locked: bool = False,
) -> Dict[str, Any]

A line chart of one or more metrics over an x-axis.

Parameters:

  • metric (Union[str, Sequence[str]]) –

    metric name, or a list of metric names to overlay in one chart.

  • x (str, default: 'step' ) –

    "step", "duration", "epoch", "wall", or any logged metric name.

  • transform_y (Optional[TransformY], default: None ) –

    None, "log" (a log-scale y-axis), "ln" (plot ln of each value), "log10" (plot log10 of each value), or "moving average".

  • smoothing (float, default: 0 ) –

    0..1 exponential smoothing factor.

  • outliers (Outliers, default: 'show' ) –

    "show" or "hide".

  • sample_size (int, default: 100 ) –

    max points fetched per curve.

  • locked (bool, default: False ) –

    True pins this panel's config against view-level changes. On a view built with global_config, x, smoothing, transform_y, outliers and sample_size come from that config unless the panel is locked.

new_id

new_id(length: int = 6) -> str

Return a random id in the same style the UI generates ('F5ReNw').

parallel_panel

parallel_panel(
    params: Sequence[str],
    metrics: Sequence[str] = (),
    target: str = "",
    name: str = "",
    precision: int = 3,
) -> Dict[str, Any]

A parallel-coordinates chart -- the standard hyperparameter sweep view.

Parameters:

  • params (Sequence[str]) –

    hyperparameter names, drawn as axes left to right.

  • metrics (Sequence[str], default: () ) –

    metric names, drawn as the right-most axes.

  • target (str, default: '' ) –

    which axis colors the lines (usually a metric, e.g. "loss").

  • precision (int, default: 3 ) –

    decimal places shown on the axes.

python_panel

python_panel(
    template_id: str = "",
    revision_id: str = "",
    name: str = "",
    code_version: str = "",
    code: Optional[str] = None,
) -> Dict[str, Any]

A Python panel, rendered server-side.

The panel gets its code in one of three ways:

  • code: the Python source, stored in the view itself, so the panel can be written from nothing.
  • template_id alone: the id of a Panel library panel, such as one uploaded with API.upload_code_panel. create_view and update_view copy that panel's code into the view when they save it, so a later upload does not change the view until it is saved again. An id the Panel library does not have makes them raise ValueError.
  • template_id and revision_id: a Python panel made in the UI's editor, read off a view with get_views(). The view refers to it.

Parameters:

  • template_id (str, default: '' ) –

    a Panel library panel, or the template of a Python panel made in the UI.

  • revision_id (str, default: '' ) –

    with template_id, the revision of a UI-made panel.

  • name (str, default: '' ) –

    the panel's title.

  • code_version (str, default: '' ) –

    a tag the page uses to know the code changed. With code, it defaults to one derived from the code.

  • code (Optional[str], default: None ) –

    the panel's Python source, stored in the view.

query_state

query_state(
    rules_tree: Optional[Dict[str, Any]] = None, segment_id: str = ""
) -> str

Serialize the filter state (experimentQueryState).

Example

query_state(any_of(all_of(rule("accuracy", "greater", 0.9))))

rule

rule(
    field: str,
    operator: str,
    value: Any,
    source: str = "metrics",
    type_: Optional[str] = None,
) -> Dict[str, Any]

One filter condition.

Parameters:

  • field (str) –

    metric / parameter / column name.

  • operator (str) –

    "greater", "less", "equal", "not_equal", "contains", "not_contains", "is_not_empty", "begins_with".

  • source (str, default: 'metrics' ) –

    "metrics", "params", "log_other", "tags", "metadata".

  • type_ (Optional[str], default: None ) –

    value type -- inferred from value when omitted ("double", "string", "boolean").

scalar_panel

scalar_panel(
    metric: str,
    aggregation: Aggregation = "last",
    name: str = "",
    precision: int = 3,
    description: Optional[str] = None,
) -> Dict[str, Any]

A single big-number tile.

Parameters:

  • aggregation (Aggregation, default: 'last' ) –

    "last", "first", "min", "max", "average", "median", "sum", ...

  • precision (int, default: 3 ) –

    decimal places shown.

  • description (Optional[str], default: None ) –

    subtitle; "" for none. Defaults to Comet's generated wording.

scatter_panel

scatter_panel(
    x: str,
    y: str,
    z: Optional[str] = None,
    name: str = "",
    aggregation: Aggregation = "last",
    metrics: Optional[List[str]] = None,
    params: Optional[List[str]] = None,
    outliers: Outliers = "show",
    sample_size: int = 100,
    legend: Optional[List[Dict[str, Any]]] = None,
) -> Dict[str, Any]

A 2D or 3D scatter plot; one point per experiment.

Axes may be metric names or hyperparameter names. Pass z for a 3D plot. metrics/params declare which of the axes are metrics vs params; when omitted every axis is treated as a metric.

table_state

table_state(
    columns: Sequence[str] = (),
    sort_by: Optional[str] = None,
    descending: bool = True,
    page_size: int = 25,
    decimals: int = 6,
    visible: bool = True,
    column_width: int = 150,
) -> str

Serialize the experiment-table configuration (reactGridTableState).

Parameters:

  • columns (Sequence[str], default: () ) –

    column ids, in display order. Metric and parameter names work directly; UI columns include "Name", "duration", "experimentTags", "end_server_timestamp", "user_name".

  • sort_by (Optional[str], default: None ) –

    column to sort on.

Nov. 4, 2026