rich.table

class rich.table.Column(header: RenderableType = '', footer: RenderableType = '', header_style: Union[str, Style] = 'table.header', footer_style: Union[str, Style] = 'table.footer', style: Union[str, Style] = 'none', justify: JustifyMethod = 'left', overflow: OverflowMethod = 'ellipsis', width: Optional[int] = None, ratio: Optional[int] = None, no_wrap: bool = False, _index: int = 0, _cells: List[RenderableType] = <factory>)[source]

Defines a column in a table.

property cells

Get all cells in the column, not including header.

property flexible

Check if this column is flexible.

footer: RenderableType = ''

Renderable for the footer (typically a string)

Type

RenderableType

footer_style: Union[str, Style] = 'table.footer'

The style of the footer.

Type

StyleType

header: RenderableType = ''

Renderable for the header (typically a string)

Type

RenderableType

header_style: Union[str, Style] = 'table.header'

The style of the header.

Type

StyleType

justify: JustifyMethod = 'left'

How to justify text within the column (“left”, “center”, “right”, or “full”)

Type

str

no_wrap: bool = False

Prevent wrapping of text within the column. Defaults to False.

Type

bool

ratio: Optional[int] = None

Ratio to use when calculating column width, or None (default) to adapt to column contents.

Type

Optional[int]

style: Union[str, Style] = 'none'

The style of the column.

Type

StyleType

width: Optional[int] = None

Width of the column, or None (default) to auto calculate width.

Type

Optional[int]

class rich.table.Table(*headers: Union[rich.table.Column, str], title: Union[str, Text] = None, caption: Union[str, Text] = None, width: int = None, box: Optional[rich.box.Box] = Box(...), safe_box: Optional[bool] = None, padding: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int, int]] = 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: Union[str, Style] = 'none', row_styles: Iterable[Union[str, Style]] = None, header_style: Union[str, Style] = None, footer_style: Union[str, Style] = None, border_style: Union[str, Style] = None, title_style: Union[str, Style] = None, caption_style: Union[str, Style] = None, title_justify: JustifyMethod = 'center', caption_justify: JustifyMethod = 'center')[source]

A console renderable to draw a table.

Parameters
  • *headers (Union[Column, str]) – Column headers, either as a string, or Column instance.

  • title (Union[str, Text], optional) – The title of the table rendered at the top. Defaults to None.

  • caption (Union[str, Text], optional) – The table caption rendered below. Defaults to None.

  • width (int, optional) – The width in characters of the table, or None to automatically fit. Defaults to None.

  • box (box.Box, optional) – One of the constants in box.py used to draw the edges (see Box). Defaults to box.HEAVY_HEAD.

  • safe_box (Optional[bool], optional) – Disable box characters that don’t display on windows legacy terminal with raster fonts. Defaults to True.

  • padding (PaddingDimensions, optional) – Padding for cells (top, right, bottom, left). Defaults to (0, 1).

  • collapse_padding (bool, optional) – Enable collapsing of padding around cells. Defaults to False.

  • pad_edge (bool, optional) – Enable padding of edge cells. Defaults to True.

  • expand (bool, optional) – Expand the table to fit the available space if True, otherwise the table width will be auto-calculated. Defaults to False.

  • show_header (bool, optional) – Show a header row. Defaults to True.

  • show_footer (bool, optional) – Show a footer row. Defaults to False.

  • show_edge (bool, optional) – Draw a box around the outside of the table. Defaults to True.

  • show_lines (bool, optional) – Draw lines between every row. Defaults to False.

  • leading (bool, optional) – Number of blank lines between rows (precludes show_lines). Defaults to 0.

  • style (Union[str, Style], optional) – Default style for the table. Defaults to “none”.

  • row_styles (List[Union, str], optional) – Optional list of row styles, if more that one style is give then the styles will alternate. Defaults to None.

  • header_style (Union[str, Style], optional) – Style of the header. Defaults to None.

  • footer_style (Union[str, Style], optional) – Style of the footer. Defaults to None.

  • border_style (Union[str, Style], optional) – Style of the border. Defaults to None.

  • title_style (Union[str, Style], optional) – Style of the title. Defaults to None.

  • caption_style (Union[str, Style], optional) – Style of the caption. Defaults to None.

  • title_justify (str, optional) – Justify method for title. Defaults to “center”.

  • caption_justify (str, optional) – Justify method for caption. Defaults to “center”.

add_column(header: RenderableType = '', footer: RenderableType = '', *, header_style: Union[str, Style] = None, footer_style: Union[str, Style] = None, style: Union[str, Style] = None, justify: JustifyMethod = 'left', overflow: OverflowMethod = 'ellipsis', width: int = None, ratio: int = None, no_wrap: bool = False) → None[source]

Add a column to the table.

Parameters
  • header (RenderableType, optional) – Text or renderable for the header. Defaults to “”.

  • footer (RenderableType, optional) – Text or renderable for the footer. Defaults to “”.

  • header_style (Union[str, Style], optional) – Style for the header. Defaults to “none”.

  • footer_style (Union[str, Style], optional) – Style for the header. Defaults to “none”.

  • style (Union[str, Style], optional) – Style for the column cells. Defaults to “none”.

  • justify (JustifyMethod, optional) – Alignment for cells. Defaults to “left”.

  • width (int, optional) – A minimum width in characters. Defaults to None.

  • ratio (int, optional) – Flexible ratio for the column (requires Table.expand or Table.width). Defaults to None.

  • no_wrap (bool, optional) – Set to True to disable wrapping of this column.

add_row(*renderables: Optional[RenderableType], style: Union[str, Style] = None) → None[source]

Add a row of renderables.

Parameters
  • *renderables (None or renderable) – Each cell in a row must be a renderable object (including str), or None for a blank cell.

  • style (StyleType, optional) – An optional style to apply to the entire row. Defaults to None.

Raises

errors.NotRenderableError – If you add something that can’t be rendered.

property expand

Setting a non-None self.width implies expand.

get_row_style(index: int) → Union[str, rich.style.Style][source]

Get the current row style.

classmethod grid(padding: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int, int]] = 0, collapse_padding: bool = True, pad_edge: bool = False, expand: bool = False)rich.table.Table[source]

Get a table with no lines, headers, or footer.

Parameters
  • padding (PaddingDimensions, optional) – Get padding around cells. Defaults to 0.

  • collapse_padding (bool, optional) – Enable collapsing of padding around cells. Defaults to True.

  • pad_edge (bool, optional) – Enable padding around edges of table. Defaults to False.

  • expand (bool, optional) – Expand the table to fit the available space if True, otherwise the table width will be auto-calculated. Defaults to False.

Returns

A table instance.

Return type

Table

property padding

Get cell padding.

property row_count

Get the current number of rows.