Skip to content

guidellm.utils.console

Console utilities for rich terminal output and status updates.

Provides an extended Rich console with custom formatting for status messages, progress tracking, and tabular data display. Includes predefined color schemes, status levels, icons, and styles for consistent terminal output across the application. Supports multi-step operations with spinners and context managers for clean progress reporting.

Colors

Color constants for console styling.

Provides standardized color schemes for different message types and branding. Colors are defined using Rich console color names or hex values.

Attributes:

Name Type Description
info str

Color for informational messages

progress str

Color for progress indicators

success str

Color for successful operations

warning str

Color for warning messages

error str

Color for error messages

primary str

Primary brand color

secondary str

Secondary brand color

tertiary str

Tertiary brand color

Source code in src/guidellm/utils/console.py
class Colors:
    """
    Color constants for console styling.

    Provides standardized color schemes for different message types and branding.
    Colors are defined using Rich console color names or hex values.

    :cvar info: Color for informational messages
    :cvar progress: Color for progress indicators
    :cvar success: Color for successful operations
    :cvar warning: Color for warning messages
    :cvar error: Color for error messages
    :cvar primary: Primary brand color
    :cvar secondary: Secondary brand color
    :cvar tertiary: Tertiary brand color
    """

    # Core states
    info: str = "light_steel_blue"
    progress: str = "dark_slate_gray1"
    success: str = "chartreuse1"
    warning: str = "#FDB516"
    error: str = "orange_red1"

    # Branding
    primary: str = "#30A2FF"
    secondary: str = "#FDB516"
    tertiary: str = "#008080"

Console

Bases: Console

Extended Rich console with custom formatting and status reporting.

Enhances Rich's Console with specialized methods for status messages, progress tracking with spinners, and formatted table output. Provides consistent styling through predefined status levels, icons, and colors. Supports quiet mode to suppress non-critical output.

Example: :: console = Console() console.print_update("Starting process", status="info") with console.print_update_step("Loading data") as step: step.update("Processing items") step.finish("Complete", status_level="success")

Source code in src/guidellm/utils/console.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
class Console(RichConsole):
    """
    Extended Rich console with custom formatting and status reporting.

    Enhances Rich's Console with specialized methods for status messages,
    progress tracking with spinners, and formatted table output. Provides
    consistent styling through predefined status levels, icons, and colors.
    Supports quiet mode to suppress non-critical output.

    Example:
    ::
        console = Console()
        console.print_update("Starting process", status="info")
        with console.print_update_step("Loading data") as step:
            step.update("Processing items")
            step.finish("Complete", status_level="success")
    """

    def print_update(
        self,
        title: str,
        details: Any | None = None,
        status: StatusLevel = "info",
    ):
        """
        Print a status message with icon and optional details.

        :param title: Main status message to display
        :param details: Optional additional details shown indented below message
        :param status: Status level determining icon and styling
        """
        icon = StatusIcons.get(status, "•")
        style = StatusStyles.get(status, "bold")
        line = Text.assemble(f"{icon} ", (title, style))
        self.print(line)
        self.print_update_details(details)

    def print_update_details(self, details: Any | None):
        """
        Print additional details indented below a status message.

        :param details: Content to display, converted to string and styled dimly
        """
        if details:
            block = Padding(
                Text.from_markup(str(details)),
                (0, 0, 0, 2),
                style=StatusStyles.get("debug", "dim"),
            )
            self.print(block)

    def print_update_step(
        self,
        title: str,
        status: StatusLevel = "info",
        details: Any | None = None,
        spinner: str = "dots",
    ) -> ConsoleUpdateStep:
        """
        Create a context manager for multi-step progress with spinner.

        :param title: Initial progress message to display
        :param status: Initial status level for styling
        :param details: Optional details to show after completion
        :param spinner: Spinner animation style name
        :return: ConsoleUpdateStep context manager for progress tracking
        """
        return ConsoleUpdateStep(
            console=self,
            title=title,
            details=details,
            status_level=status,
            spinner=spinner,
        )

    def print_tables(
        self,
        header_cols_groups: Sequence[Sequence[str | list[str]]],
        value_cols_groups: Sequence[Sequence[str | list[str]]],
        title: str | None = None,
        widths: Sequence[int] | None = None,
    ):
        """
        Print multiple tables with uniform column widths.

        :param header_cols_groups: List of header column groups for each table
        :param value_cols_groups: List of value column groups for each table
        :param title: Optional title to display before tables
        :param widths: Optional minimum column widths to enforce
        """
        if title is not None:
            self.print_update(title, None, "info")

        # Format all groups to determine uniform widths
        widths = widths or None
        headers = []
        values = []

        # Process all tables to get consistent widths
        for value_cols in value_cols_groups:
            formatted, widths = self._format_table_columns(value_cols, widths)
            values.append(formatted)
        for header_cols in header_cols_groups:
            formatted, widths = self._format_table_headers(header_cols, widths)
            headers.append(formatted)

        # Print each table
        for ind, (header, value) in enumerate(zip(headers, values, strict=False)):
            is_last = ind == len(headers) - 1
            self.print_table(
                header,
                value,
                widths=widths,
                apply_formatting=False,
                print_bottom_divider=is_last,
            )

    def print_table(
        self,
        header_cols: Sequence[str | list[str]],
        value_cols: Sequence[str | list[str]],
        title: str | None = None,
        widths: Sequence[int] | None = None,
        apply_formatting: bool = True,
        print_bottom_divider: bool = True,
    ):
        """
        Print a formatted table with headers and values.

        :param header_cols: List of header columns, each string or list of strings
        :param value_cols: List of value columns, each string or list of strings
        :param title: Optional title to display before table
        :param widths: Optional minimum column widths to enforce
        :param apply_formatting: Whether to calculate widths and format columns
        :param print_bottom_divider: Whether to print bottom border line
        """
        if title is not None:
            self.print_update(title, None, "info")

        # Format data
        values: list[list[str]]
        headers: list[list[str]]
        final_widths: list[int]

        if apply_formatting:
            values, final_widths = self._format_table_columns(value_cols, widths)
            headers, final_widths = self._format_table_headers(
                header_cols, final_widths
            )
        else:
            values = [col if isinstance(col, list) else [col] for col in value_cols]
            headers = [col if isinstance(col, list) else [col] for col in header_cols]
            final_widths = list(widths) if widths else []

        # Print table structure
        self.print_table_divider(final_widths, "=")
        self.print_table_headers(headers, final_widths)
        self.print_table_divider(final_widths, "-")
        self.print_table_values(values, final_widths)

        if print_bottom_divider:
            self.print_table_divider(final_widths, "=")

    def print_table_divider(self, widths: Sequence[int], char: str):
        """
        Print a horizontal divider line across table columns.

        :param widths: Column widths for divider line
        :param char: Character to use for divider line (e.g., '=', '-')
        """
        self.print_table_row(
            [""] * len(widths),
            widths=widths,
            spacer=char,
            cell_style="bold",
            divider_style="bold",
            edge_style="bold",
        )

    def print_table_headers(self, headers: Sequence[list[str]], widths: Sequence[int]):
        """
        Print header rows with support for column spanning.

        :param headers: List of header columns, each containing header row values
        :param widths: Column widths for proper alignment
        """
        if not headers or not headers[0]:
            return

        for row_idx in range(len(headers[0])):
            # Calculate widths for this header row, accounting for merged cells.
            row_widths = list(widths)
            for col_idx in range(len(headers)):
                if not headers[col_idx][row_idx]:
                    continue

                # Find span end
                span_end = col_idx + 1
                while span_end < len(headers) and not headers[span_end][row_idx]:
                    row_widths[span_end] = 0
                    span_end += 1

                # Set combined width for the first cell in span
                row_widths[col_idx] = sum(
                    widths[col] for col in range(col_idx, span_end)
                )

            # Print the header row
            self.print_table_row(
                values=[headers[col][row_idx] for col in range(len(headers))],
                widths=row_widths,
                cell_style="bold",
                divider_style="bold",
                edge_style="bold",
            )

    def print_table_values(self, values: Sequence[list[str]], widths: Sequence[int]):
        """
        Print all data rows in the table.

        :param values: List of value columns, each containing row values
        :param widths: Column widths for proper alignment
        """
        if not values:
            return

        for row_idx in range(len(values[0])):
            # Print the value row
            self.print_table_row(
                values=[values[col][row_idx] for col in range(len(values))],
                widths=widths,
                divider="|",
                edge_style="bold",
            )

    def print_table_row(
        self,
        values: Sequence[str],
        widths: Sequence[int] | None = None,
        spacer: str = " ",
        divider: str = "|",
        cell_style: str = "",
        value_style: str = "",
        divider_style: str = "",
        edge_style: str = "",
    ):
        """
        Print a single table row with custom styling.

        :param values: Cell values for the row
        :param widths: Column widths, defaults to value lengths
        :param spacer: Character for padding cells
        :param divider: Character separating columns
        :param cell_style: Rich style string for entire cells
        :param value_style: Rich style string for cell values only
        :param divider_style: Rich style string for column dividers
        :param edge_style: Rich style string for table edges
        """
        widths = widths or [len(val) for val in values]

        # Build styled cells
        cells = []
        for val, width in zip(values, widths, strict=True):
            cell = val.ljust(width, spacer)
            if value_style and val:
                cell = cell.replace(val, f"[{value_style}]{val}[/{value_style}]")
            if cell_style:
                cell = f"[{cell_style}]{cell}[/{cell_style}]"
            cells.append(cell)

        # Build and print row
        edge = f"[{edge_style}]{divider}[/{edge_style}]" if edge_style else divider
        inner = (
            f"[{divider_style}]{divider}[/{divider_style}]"
            if divider_style
            else divider
        )
        line = edge + inner.join(cells) + edge
        self.print(line, overflow="ignore", crop=False)

    def _format_table_headers(
        self,
        headers: Sequence[str | list[str]],
        col_widths: Sequence[int] | None = None,
        spacer: str = " ",
        min_padding: int = 1,
    ) -> tuple[list[list[str]], list[int]]:
        formatted, header_widths = self._format_table_columns(
            headers, col_widths, spacer, min_padding
        )

        if not formatted or not formatted[0]:
            return formatted, []

        # Merge identical adjacent headers row by row
        widths = list(col_widths) if col_widths else header_widths
        for row_idx in range(len(formatted[0])):
            last_value = None
            start_col = -1

            for col_idx in range(len(formatted) + 1):
                cur_value = (
                    formatted[col_idx][row_idx] if col_idx < len(formatted) else None
                )

                # Check if we should continue merging
                if (
                    col_idx < len(formatted)
                    and cur_value != ""
                    and cur_value == last_value
                    and (
                        row_idx == 0
                        or headers[start_col][row_idx - 1]
                        == headers[col_idx][row_idx - 1]
                    )
                ):
                    continue

                # Finalize previous
                if start_col >= 0:
                    # Clear merged cells to keep only the first
                    for col in range(start_col + 1, col_idx):
                        formatted[col][row_idx] = ""

                    # Adjust widths of columns in the merged span, if needed
                    if (required := len(formatted[start_col][row_idx])) > (
                        current := sum(widths[col] for col in range(start_col, col_idx))
                    ):
                        diff = required - current
                        cols_count = col_idx - start_col
                        per_col = diff // cols_count
                        extra = diff % cols_count

                        for col in range(start_col, col_idx):
                            widths[col] += per_col
                            if extra > 0:
                                widths[col] += 1
                                extra -= 1

                # Start new merge
                last_value = cur_value
                start_col = col_idx

        return formatted, widths

    def _format_table_columns(
        self,
        columns: Sequence[str | list[str]],
        col_widths: Sequence[int] | None = None,
        spacer: str = " ",
        min_padding: int = 1,
    ) -> tuple[list[list[str]], list[int]]:
        if not columns:
            return [], []

        # Normalize to list of lists
        max_rows = max(len(col) if isinstance(col, list) else 1 for col in columns)

        formatted = []
        for col in columns:
            col_list = col if isinstance(col, list) else [col]
            # Pad to max height
            col_list = col_list + [""] * (max_rows - len(col_list))
            # Add cell padding
            padding = spacer * min_padding
            col_list = [
                f"{padding}{item}{padding}" if item else "" for item in col_list
            ]
            formatted.append(col_list)

        # Calculate widths
        widths = [max(len(row) for row in col) for col in formatted]

        # Apply minimum widths if provided
        if col_widths is not None:
            widths = [
                max(width, min_w)
                for width, min_w in zip(widths, col_widths, strict=True)
            ]

        return formatted, widths

print_table(header_cols, value_cols, title=None, widths=None, apply_formatting=True, print_bottom_divider=True)

Print a formatted table with headers and values.

Parameters:

Name Type Description Default
header_cols Sequence[str | list[str]]

List of header columns, each string or list of strings

required
value_cols Sequence[str | list[str]]

List of value columns, each string or list of strings

required
title str | None

Optional title to display before table

None
widths Sequence[int] | None

Optional minimum column widths to enforce

None
apply_formatting bool

Whether to calculate widths and format columns

True
print_bottom_divider bool

Whether to print bottom border line

True
Source code in src/guidellm/utils/console.py
def print_table(
    self,
    header_cols: Sequence[str | list[str]],
    value_cols: Sequence[str | list[str]],
    title: str | None = None,
    widths: Sequence[int] | None = None,
    apply_formatting: bool = True,
    print_bottom_divider: bool = True,
):
    """
    Print a formatted table with headers and values.

    :param header_cols: List of header columns, each string or list of strings
    :param value_cols: List of value columns, each string or list of strings
    :param title: Optional title to display before table
    :param widths: Optional minimum column widths to enforce
    :param apply_formatting: Whether to calculate widths and format columns
    :param print_bottom_divider: Whether to print bottom border line
    """
    if title is not None:
        self.print_update(title, None, "info")

    # Format data
    values: list[list[str]]
    headers: list[list[str]]
    final_widths: list[int]

    if apply_formatting:
        values, final_widths = self._format_table_columns(value_cols, widths)
        headers, final_widths = self._format_table_headers(
            header_cols, final_widths
        )
    else:
        values = [col if isinstance(col, list) else [col] for col in value_cols]
        headers = [col if isinstance(col, list) else [col] for col in header_cols]
        final_widths = list(widths) if widths else []

    # Print table structure
    self.print_table_divider(final_widths, "=")
    self.print_table_headers(headers, final_widths)
    self.print_table_divider(final_widths, "-")
    self.print_table_values(values, final_widths)

    if print_bottom_divider:
        self.print_table_divider(final_widths, "=")

print_table_divider(widths, char)

Print a horizontal divider line across table columns.

Parameters:

Name Type Description Default
widths Sequence[int]

Column widths for divider line

required
char str

Character to use for divider line (e.g., '=', '-')

required
Source code in src/guidellm/utils/console.py
def print_table_divider(self, widths: Sequence[int], char: str):
    """
    Print a horizontal divider line across table columns.

    :param widths: Column widths for divider line
    :param char: Character to use for divider line (e.g., '=', '-')
    """
    self.print_table_row(
        [""] * len(widths),
        widths=widths,
        spacer=char,
        cell_style="bold",
        divider_style="bold",
        edge_style="bold",
    )

print_table_headers(headers, widths)

Print header rows with support for column spanning.

Parameters:

Name Type Description Default
headers Sequence[list[str]]

List of header columns, each containing header row values

required
widths Sequence[int]

Column widths for proper alignment

required
Source code in src/guidellm/utils/console.py
def print_table_headers(self, headers: Sequence[list[str]], widths: Sequence[int]):
    """
    Print header rows with support for column spanning.

    :param headers: List of header columns, each containing header row values
    :param widths: Column widths for proper alignment
    """
    if not headers or not headers[0]:
        return

    for row_idx in range(len(headers[0])):
        # Calculate widths for this header row, accounting for merged cells.
        row_widths = list(widths)
        for col_idx in range(len(headers)):
            if not headers[col_idx][row_idx]:
                continue

            # Find span end
            span_end = col_idx + 1
            while span_end < len(headers) and not headers[span_end][row_idx]:
                row_widths[span_end] = 0
                span_end += 1

            # Set combined width for the first cell in span
            row_widths[col_idx] = sum(
                widths[col] for col in range(col_idx, span_end)
            )

        # Print the header row
        self.print_table_row(
            values=[headers[col][row_idx] for col in range(len(headers))],
            widths=row_widths,
            cell_style="bold",
            divider_style="bold",
            edge_style="bold",
        )

print_table_row(values, widths=None, spacer=' ', divider='|', cell_style='', value_style='', divider_style='', edge_style='')

Print a single table row with custom styling.

Parameters:

Name Type Description Default
values Sequence[str]

Cell values for the row

required
widths Sequence[int] | None

Column widths, defaults to value lengths

None
spacer str

Character for padding cells

' '
divider str

Character separating columns

'|'
cell_style str

Rich style string for entire cells

''
value_style str

Rich style string for cell values only

''
divider_style str

Rich style string for column dividers

''
edge_style str

Rich style string for table edges

''
Source code in src/guidellm/utils/console.py
def print_table_row(
    self,
    values: Sequence[str],
    widths: Sequence[int] | None = None,
    spacer: str = " ",
    divider: str = "|",
    cell_style: str = "",
    value_style: str = "",
    divider_style: str = "",
    edge_style: str = "",
):
    """
    Print a single table row with custom styling.

    :param values: Cell values for the row
    :param widths: Column widths, defaults to value lengths
    :param spacer: Character for padding cells
    :param divider: Character separating columns
    :param cell_style: Rich style string for entire cells
    :param value_style: Rich style string for cell values only
    :param divider_style: Rich style string for column dividers
    :param edge_style: Rich style string for table edges
    """
    widths = widths or [len(val) for val in values]

    # Build styled cells
    cells = []
    for val, width in zip(values, widths, strict=True):
        cell = val.ljust(width, spacer)
        if value_style and val:
            cell = cell.replace(val, f"[{value_style}]{val}[/{value_style}]")
        if cell_style:
            cell = f"[{cell_style}]{cell}[/{cell_style}]"
        cells.append(cell)

    # Build and print row
    edge = f"[{edge_style}]{divider}[/{edge_style}]" if edge_style else divider
    inner = (
        f"[{divider_style}]{divider}[/{divider_style}]"
        if divider_style
        else divider
    )
    line = edge + inner.join(cells) + edge
    self.print(line, overflow="ignore", crop=False)

print_table_values(values, widths)

Print all data rows in the table.

Parameters:

Name Type Description Default
values Sequence[list[str]]

List of value columns, each containing row values

required
widths Sequence[int]

Column widths for proper alignment

required
Source code in src/guidellm/utils/console.py
def print_table_values(self, values: Sequence[list[str]], widths: Sequence[int]):
    """
    Print all data rows in the table.

    :param values: List of value columns, each containing row values
    :param widths: Column widths for proper alignment
    """
    if not values:
        return

    for row_idx in range(len(values[0])):
        # Print the value row
        self.print_table_row(
            values=[values[col][row_idx] for col in range(len(values))],
            widths=widths,
            divider="|",
            edge_style="bold",
        )

print_tables(header_cols_groups, value_cols_groups, title=None, widths=None)

Print multiple tables with uniform column widths.

Parameters:

Name Type Description Default
header_cols_groups Sequence[Sequence[str | list[str]]]

List of header column groups for each table

required
value_cols_groups Sequence[Sequence[str | list[str]]]

List of value column groups for each table

required
title str | None

Optional title to display before tables

None
widths Sequence[int] | None

Optional minimum column widths to enforce

None
Source code in src/guidellm/utils/console.py
def print_tables(
    self,
    header_cols_groups: Sequence[Sequence[str | list[str]]],
    value_cols_groups: Sequence[Sequence[str | list[str]]],
    title: str | None = None,
    widths: Sequence[int] | None = None,
):
    """
    Print multiple tables with uniform column widths.

    :param header_cols_groups: List of header column groups for each table
    :param value_cols_groups: List of value column groups for each table
    :param title: Optional title to display before tables
    :param widths: Optional minimum column widths to enforce
    """
    if title is not None:
        self.print_update(title, None, "info")

    # Format all groups to determine uniform widths
    widths = widths or None
    headers = []
    values = []

    # Process all tables to get consistent widths
    for value_cols in value_cols_groups:
        formatted, widths = self._format_table_columns(value_cols, widths)
        values.append(formatted)
    for header_cols in header_cols_groups:
        formatted, widths = self._format_table_headers(header_cols, widths)
        headers.append(formatted)

    # Print each table
    for ind, (header, value) in enumerate(zip(headers, values, strict=False)):
        is_last = ind == len(headers) - 1
        self.print_table(
            header,
            value,
            widths=widths,
            apply_formatting=False,
            print_bottom_divider=is_last,
        )

print_update(title, details=None, status='info')

Print a status message with icon and optional details.

Parameters:

Name Type Description Default
title str

Main status message to display

required
details Any | None

Optional additional details shown indented below message

None
status StatusLevel

Status level determining icon and styling

'info'
Source code in src/guidellm/utils/console.py
def print_update(
    self,
    title: str,
    details: Any | None = None,
    status: StatusLevel = "info",
):
    """
    Print a status message with icon and optional details.

    :param title: Main status message to display
    :param details: Optional additional details shown indented below message
    :param status: Status level determining icon and styling
    """
    icon = StatusIcons.get(status, "•")
    style = StatusStyles.get(status, "bold")
    line = Text.assemble(f"{icon} ", (title, style))
    self.print(line)
    self.print_update_details(details)

print_update_details(details)

Print additional details indented below a status message.

Parameters:

Name Type Description Default
details Any | None

Content to display, converted to string and styled dimly

required
Source code in src/guidellm/utils/console.py
def print_update_details(self, details: Any | None):
    """
    Print additional details indented below a status message.

    :param details: Content to display, converted to string and styled dimly
    """
    if details:
        block = Padding(
            Text.from_markup(str(details)),
            (0, 0, 0, 2),
            style=StatusStyles.get("debug", "dim"),
        )
        self.print(block)

print_update_step(title, status='info', details=None, spinner='dots')

Create a context manager for multi-step progress with spinner.

Parameters:

Name Type Description Default
title str

Initial progress message to display

required
status StatusLevel

Initial status level for styling

'info'
details Any | None

Optional details to show after completion

None
spinner str

Spinner animation style name

'dots'

Returns:

Type Description
ConsoleUpdateStep

ConsoleUpdateStep context manager for progress tracking

Source code in src/guidellm/utils/console.py
def print_update_step(
    self,
    title: str,
    status: StatusLevel = "info",
    details: Any | None = None,
    spinner: str = "dots",
) -> ConsoleUpdateStep:
    """
    Create a context manager for multi-step progress with spinner.

    :param title: Initial progress message to display
    :param status: Initial status level for styling
    :param details: Optional details to show after completion
    :param spinner: Spinner animation style name
    :return: ConsoleUpdateStep context manager for progress tracking
    """
    return ConsoleUpdateStep(
        console=self,
        title=title,
        details=details,
        status_level=status,
        spinner=spinner,
    )

ConsoleUpdateStep dataclass

Context manager for multi-step progress operations with spinner.

Displays animated spinner during operation execution and allows dynamic status updates. Automatically stops spinner on exit and prints final status message. Designed for use with Python's with statement.

Example: :: console = Console() with console.print_update_step("Processing data") as step: step.update("Loading files", "info") # ... do work ... step.finish("Completed successfully", status_level="success")

Parameters:

Name Type Description Default
console Console

The Console instance to use for output

required
title str

Initial progress message to display

required
details Any | None

Optional additional details to show after completion

None
status_level StatusLevel

Initial status level determining style and icon

'info'
spinner str

Spinner animation style name from Rich's spinner set

'dots'
Source code in src/guidellm/utils/console.py
@dataclass
class ConsoleUpdateStep:
    """
    Context manager for multi-step progress operations with spinner.

    Displays animated spinner during operation execution and allows dynamic
    status updates. Automatically stops spinner on exit and prints final
    status message. Designed for use with Python's `with` statement.

    Example:
    ::
        console = Console()
        with console.print_update_step("Processing data") as step:
            step.update("Loading files", "info")
            # ... do work ...
            step.finish("Completed successfully", status_level="success")

    :param console: The Console instance to use for output
    :param title: Initial progress message to display
    :param details: Optional additional details to show after completion
    :param status_level: Initial status level determining style and icon
    :param spinner: Spinner animation style name from Rich's spinner set
    """

    console: Console
    title: str
    details: Any | None = None
    status_level: StatusLevel = "info"
    spinner: str = "dots"
    _status: Status | None = None

    def __enter__(self) -> ConsoleUpdateStep:
        if self.console.quiet:
            return self

        style = StatusStyles.get(self.status_level, "bold")
        self._status = self.console.status(
            f"[{style}]{self.title}[/]",
            spinner=self.spinner,
        )
        self._status.__enter__()
        return self

    def update(self, title: str, status_level: StatusLevel | None = None):
        """
        Update the progress message and optionally the status level.

        :param title: New progress message to display
        :param status_level: Optional new status level to apply
        """
        self.title = title
        if status_level is not None:
            self.status_level = status_level

        if self._status:
            style = StatusStyles.get(self.status_level, "bold")
            self._status.update(status=f"[{style}]{title}[/]")

    def finish(
        self,
        title: str,
        details: Any | None = None,
        status_level: StatusLevel = "info",
    ):
        """
        Stop the spinner and print the final status message.

        :param title: Final completion message to display
        :param details: Optional additional information to show below message
        :param status_level: Status level for final message styling
        """
        self.title = title
        self.status_level = status_level

        if self._status:
            self._status.stop()

        self.console.print_update(title, details, status_level)

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self._status:
            self._status.__exit__(exc_type, exc_val, exc_tb)

finish(title, details=None, status_level='info')

Stop the spinner and print the final status message.

Parameters:

Name Type Description Default
title str

Final completion message to display

required
details Any | None

Optional additional information to show below message

None
status_level StatusLevel

Status level for final message styling

'info'
Source code in src/guidellm/utils/console.py
def finish(
    self,
    title: str,
    details: Any | None = None,
    status_level: StatusLevel = "info",
):
    """
    Stop the spinner and print the final status message.

    :param title: Final completion message to display
    :param details: Optional additional information to show below message
    :param status_level: Status level for final message styling
    """
    self.title = title
    self.status_level = status_level

    if self._status:
        self._status.stop()

    self.console.print_update(title, details, status_level)

update(title, status_level=None)

Update the progress message and optionally the status level.

Parameters:

Name Type Description Default
title str

New progress message to display

required
status_level StatusLevel | None

Optional new status level to apply

None
Source code in src/guidellm/utils/console.py
def update(self, title: str, status_level: StatusLevel | None = None):
    """
    Update the progress message and optionally the status level.

    :param title: New progress message to display
    :param status_level: Optional new status level to apply
    """
    self.title = title
    if status_level is not None:
        self.status_level = status_level

    if self._status:
        style = StatusStyles.get(self.status_level, "bold")
        self._status.update(status=f"[{style}]{title}[/]")