Skip to content

Table Reference

Bases: Gradient

A Rich table convenience constructor with gradient rendering.

Parameters:

Name Type Description Default
headers str | Column

Optional Rich table headers or Column instances.

()
title TextType | None

Optional title rendered above the table.

None
caption TextType | None

Optional caption rendered below the table.

None
width int | None

Optional explicit table width.

None
min_width int | None

Optional minimum table width.

None
box Box | None

Rich box style for table borders.

HEAVY_HEAD
safe_box bool | None

Whether to use safe box drawing characters.

None
padding PaddingDimensions

Padding for table cells.

(0, 1)
collapse_padding bool

Whether to collapse cell padding.

False
pad_edge bool

Whether to pad edge cells.

True
expand bool

Whether the table expands to fill available width.

False
show_header bool

Whether to show the header row.

True
show_footer bool

Whether to show the footer row.

False
show_edge bool

Whether to draw outer table edges.

True
show_lines bool

Whether to draw lines between rows.

False
leading int

Blank lines between rows.

0
style StyleType

Base table style.

'none'
row_styles Sequence[StyleType] | None

Optional alternating row styles.

None
header_style StyleType

Header style.

'table.header'
footer_style StyleType

Footer style.

'table.footer'
border_style StyleType | None

Optional border style.

None
title_style StyleType | None

Optional title style.

None
caption_style StyleType | None

Optional caption style.

None
title_justify AlignMethod

Title justification.

'center'
caption_justify AlignMethod

Caption justification.

'center'
highlight bool

Whether Rich should highlight cell contents.

False
colors Optional[Sequence[ColorType]]

Foreground gradient color stops.

None
bg_colors Optional[Sequence[ColorType]]

Background gradient color stops.

None
rainbow bool

Whether to generate a rainbow palette.

False
hues int

Number of auto-generated hues.

5
repeat_scale float

Scale factor controlling gradient repeats.

2.0
justify AlignMethod

Horizontal alignment of the table in the gradient frame.

'left'
vertical_justify VerticalAlignMethod

Vertical alignment of the table in the gradient frame.

'middle'
console Optional[Console]

Optional Rich console.

None
highlight_words Optional[HighlightWordsType]

Word highlight configuration.

None
highlight_regex Optional[HighlightRegexType]

Regex highlight configuration.

None
Source code in src/rich_gradient/table.py
class Table(Gradient):
    """A Rich table convenience constructor with gradient rendering.

    Args:
        headers: Optional Rich table headers or `Column` instances.
        title: Optional title rendered above the table.
        caption: Optional caption rendered below the table.
        width: Optional explicit table width.
        min_width: Optional minimum table width.
        box: Rich box style for table borders.
        safe_box: Whether to use safe box drawing characters.
        padding: Padding for table cells.
        collapse_padding: Whether to collapse cell padding.
        pad_edge: Whether to pad edge cells.
        expand: Whether the table expands to fill available width.
        show_header: Whether to show the header row.
        show_footer: Whether to show the footer row.
        show_edge: Whether to draw outer table edges.
        show_lines: Whether to draw lines between rows.
        leading: Blank lines between rows.
        style: Base table style.
        row_styles: Optional alternating row styles.
        header_style: Header style.
        footer_style: Footer style.
        border_style: Optional border style.
        title_style: Optional title style.
        caption_style: Optional caption style.
        title_justify: Title justification.
        caption_justify: Caption justification.
        highlight: Whether Rich should highlight cell contents.
        colors: Foreground gradient color stops.
        bg_colors: Background gradient color stops.
        rainbow: Whether to generate a rainbow palette.
        hues: Number of auto-generated hues.
        repeat_scale: Scale factor controlling gradient repeats.
        justify: Horizontal alignment of the table in the gradient frame.
        vertical_justify: Vertical alignment of the table in the gradient frame.
        console: Optional Rich console.
        highlight_words: Word highlight configuration.
        highlight_regex: Regex highlight configuration.
    """

    def __init__(
        self,
        *headers: str | Column,
        title: TextType | None = None,
        caption: TextType | None = None,
        width: int | None = None,
        min_width: int | None = None,
        box: Box | None = HEAVY_HEAD,
        safe_box: bool | None = None,
        padding: PaddingDimensions = (0, 1),
        collapse_padding: bool = False,
        pad_edge: bool = True,
        expand: bool = False,
        show_header: bool = True,
        show_footer: bool = False,
        show_edge: bool = True,
        show_lines: bool = False,
        leading: int = 0,
        style: StyleType = "none",
        row_styles: Sequence[StyleType] | None = None,
        header_style: StyleType = "table.header",
        footer_style: StyleType = "table.footer",
        border_style: StyleType | None = None,
        title_style: StyleType | None = None,
        caption_style: StyleType | None = None,
        title_justify: AlignMethod = "center",
        caption_justify: AlignMethod = "center",
        highlight: bool = False,
        colors: Optional[Sequence[ColorType]] = None,
        bg_colors: Optional[Sequence[ColorType]] = None,
        rainbow: bool = False,
        hues: int = 5,
        repeat_scale: float = 2.0,
        justify: AlignMethod = "left",
        vertical_justify: VerticalAlignMethod = "middle",
        console: Optional[Console] = None,
        highlight_words: Optional[HighlightWordsType] = None,
        highlight_regex: Optional[HighlightRegexType] = None,
    ) -> None:
        """Initialize a gradient-enabled Rich table."""
        table = RichTable(
            *headers,
            title=title,
            caption=caption,
            width=width,
            min_width=min_width,
            box=box,
            safe_box=safe_box,
            padding=padding,
            collapse_padding=collapse_padding,
            pad_edge=pad_edge,
            expand=expand,
            show_header=show_header,
            show_footer=show_footer,
            show_edge=show_edge,
            show_lines=show_lines,
            leading=leading,
            style=style,
            row_styles=list(row_styles) if row_styles is not None else None,
            header_style=header_style,
            footer_style=footer_style,
            border_style=border_style,
            title_style=title_style,
            caption_style=caption_style,
            title_justify=title_justify,
            caption_justify=caption_justify,
            highlight=highlight,
        )
        self._table = table
        super().__init__(
            table,
            colors=list(colors) if colors is not None else None,
            bg_colors=list(bg_colors) if bg_colors is not None else None,
            console=console,
            hues=hues,
            rainbow=rainbow,
            expand=expand,
            justify=justify,
            vertical_justify=vertical_justify,
            repeat_scale=repeat_scale,
            highlight_words=highlight_words,
            highlight_regex=highlight_regex,
        )

    @property
    def table(self) -> RichTable:
        """Return the underlying Rich table."""
        return self._table

    def add_column(self, *args: Any, **kwargs: Any) -> None:
        """Forward `add_column` to the underlying Rich table."""
        self._table.add_column(*args, **kwargs)

    def add_row(self, *args: RenderableType, **kwargs: Any) -> None:
        """Forward `add_row` to the underlying Rich table."""
        self._table.add_row(*args, **kwargs)

table property

Return the underlying Rich table.

__init__(*headers, title=None, caption=None, width=None, min_width=None, box=HEAVY_HEAD, safe_box=None, padding=(0, 1), collapse_padding=False, pad_edge=True, expand=False, show_header=True, show_footer=False, show_edge=True, show_lines=False, leading=0, style='none', row_styles=None, header_style='table.header', footer_style='table.footer', border_style=None, title_style=None, caption_style=None, title_justify='center', caption_justify='center', highlight=False, colors=None, bg_colors=None, rainbow=False, hues=5, repeat_scale=2.0, justify='left', vertical_justify='middle', console=None, highlight_words=None, highlight_regex=None)

Initialize a gradient-enabled Rich table.

Source code in src/rich_gradient/table.py
def __init__(
    self,
    *headers: str | Column,
    title: TextType | None = None,
    caption: TextType | None = None,
    width: int | None = None,
    min_width: int | None = None,
    box: Box | None = HEAVY_HEAD,
    safe_box: bool | None = None,
    padding: PaddingDimensions = (0, 1),
    collapse_padding: bool = False,
    pad_edge: bool = True,
    expand: bool = False,
    show_header: bool = True,
    show_footer: bool = False,
    show_edge: bool = True,
    show_lines: bool = False,
    leading: int = 0,
    style: StyleType = "none",
    row_styles: Sequence[StyleType] | None = None,
    header_style: StyleType = "table.header",
    footer_style: StyleType = "table.footer",
    border_style: StyleType | None = None,
    title_style: StyleType | None = None,
    caption_style: StyleType | None = None,
    title_justify: AlignMethod = "center",
    caption_justify: AlignMethod = "center",
    highlight: bool = False,
    colors: Optional[Sequence[ColorType]] = None,
    bg_colors: Optional[Sequence[ColorType]] = None,
    rainbow: bool = False,
    hues: int = 5,
    repeat_scale: float = 2.0,
    justify: AlignMethod = "left",
    vertical_justify: VerticalAlignMethod = "middle",
    console: Optional[Console] = None,
    highlight_words: Optional[HighlightWordsType] = None,
    highlight_regex: Optional[HighlightRegexType] = None,
) -> None:
    """Initialize a gradient-enabled Rich table."""
    table = RichTable(
        *headers,
        title=title,
        caption=caption,
        width=width,
        min_width=min_width,
        box=box,
        safe_box=safe_box,
        padding=padding,
        collapse_padding=collapse_padding,
        pad_edge=pad_edge,
        expand=expand,
        show_header=show_header,
        show_footer=show_footer,
        show_edge=show_edge,
        show_lines=show_lines,
        leading=leading,
        style=style,
        row_styles=list(row_styles) if row_styles is not None else None,
        header_style=header_style,
        footer_style=footer_style,
        border_style=border_style,
        title_style=title_style,
        caption_style=caption_style,
        title_justify=title_justify,
        caption_justify=caption_justify,
        highlight=highlight,
    )
    self._table = table
    super().__init__(
        table,
        colors=list(colors) if colors is not None else None,
        bg_colors=list(bg_colors) if bg_colors is not None else None,
        console=console,
        hues=hues,
        rainbow=rainbow,
        expand=expand,
        justify=justify,
        vertical_justify=vertical_justify,
        repeat_scale=repeat_scale,
        highlight_words=highlight_words,
        highlight_regex=highlight_regex,
    )

add_column(*args, **kwargs)

Forward add_column to the underlying Rich table.

Source code in src/rich_gradient/table.py
def add_column(self, *args: Any, **kwargs: Any) -> None:
    """Forward `add_column` to the underlying Rich table."""
    self._table.add_column(*args, **kwargs)

add_row(*args, **kwargs)

Forward add_row to the underlying Rich table.

Source code in src/rich_gradient/table.py
def add_row(self, *args: RenderableType, **kwargs: Any) -> None:
    """Forward `add_row` to the underlying Rich table."""
    self._table.add_row(*args, **kwargs)