rich.table

class rich.table.Column(header='', footer='', header_style='', footer_style='', style='', justify='left', vertical='top', overflow='ellipsis', width=None, min_width=None, max_width=None, ratio=None, no_wrap=False, _index=0, _cells=<factory>)[source]

Defines a column within a ~Table.

Parameters
  • 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.

  • min_width (Optional[int], optional) – The minimum width of the table, or None for no minimum. Defaults to None.

  • box (box.Box, optional) – One of the constants in box.py used to draw the edges (see Box), or None for no box lines. 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 than one style is given then the styles will alternate. Defaults to None.

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

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

  • 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”.

  • highlight (bool, optional) – Highlight cell contents (if str). Defaults to False.

  • header (RenderableType) –

  • footer (RenderableType) –

  • justify (JustifyMethod) –

  • vertical (VerticalAlignMethod) –

  • overflow (OverflowMethod) –

  • max_width (Optional[int]) –

  • ratio (Optional[int]) –

  • no_wrap (bool) –

  • _index (int) –

  • _cells (List[RenderableType]) –

property cells: Iterable[RenderableType]

Get all cells in the column, not including header.

copy()[source]

Return a copy of this Column.

Return type

Column

property flexible: bool

Check if this column is flexible.

footer: RenderableType = ''

Renderable for the footer (typically a string)

Type

RenderableType

footer_style: Union[str, Style] = ''

The style of the footer.

Type

StyleType

header: RenderableType = ''

Renderable for the header (typically a string)

Type

RenderableType

header_style: Union[str, Style] = ''

The style of the header.

Type

StyleType

justify: JustifyMethod = 'left'

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

Type

str

max_width: Optional[int] = None

Maximum width of column, or None for no maximum. Defaults to None.

Type

Optional[int]

min_width: Optional[int] = None

Minimum width of column, or None for no minimum. Defaults to None.

Type

Optional[int]

no_wrap: bool = False

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

Type

bool

overflow: OverflowMethod = 'ellipsis'

Overflow method.

Type

str

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] = ''

The style of the column.

Type

StyleType

vertical: VerticalAlignMethod = 'top'

How to vertically align content (“top”, “middle”, or “bottom”)

Type

str

width: Optional[int] = None

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

Type

Optional[int]

class rich.table.Row(style=None, end_section=False)[source]

Information regarding a row.

Parameters
end_section: bool = False

Indicated end of section, which will force a line beneath the row.

style: Optional[Union[str, Style]] = None

Style to apply to row.

class rich.table.Table(*headers, title=None, caption=None, width=None, min_width=None, box=Box(...), 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)[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.

  • min_width (Optional[int], optional) – The minimum width of the table, or None for no minimum. Defaults to None.

  • box (box.Box, optional) – One of the constants in box.py used to draw the edges (see Box), or None for no box lines. 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 than one style is given then the styles will alternate. Defaults to None.

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

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

  • 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”.

  • highlight (bool, optional) – Highlight cell contents (if str). Defaults to False.

add_column(header='', footer='', *, header_style=None, footer_style=None, style=None, justify='left', vertical='top', overflow='ellipsis', width=None, min_width=None, max_width=None, ratio=None, no_wrap=False)[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, or None for default. Defaults to None.

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

  • style (Union[str, Style], optional) – Style for the column cells, or None for default. Defaults to None.

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

  • vertical (VerticalAlignMethod, optional) – Vertical alignment, one of “top”, “middle”, or “bottom”. Defaults to “top”.

  • overflow (OverflowMethod) – Overflow method: “crop”, “fold”, “ellipsis”. Defaults to “ellipsis”.

  • width (int, optional) – Desired width of column in characters, or None to fit to contents. Defaults to None.

  • min_width (Optional[int], optional) – Minimum width of column, or None for no minimum. Defaults to None.

  • max_width (Optional[int], optional) – Maximum width of column, or None for no maximum. 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.

Return type

None

add_row(*renderables, style=None, end_section=False)[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.

  • end_section (bool, optional) – End a section and draw a line. Defaults to False.

Raises

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

Return type

None

add_section()[source]

Add a new section (draw a line after current row).

Return type

None

property expand: bool

Setting a non-None self.width implies expand.

get_row_style(console, index)[source]

Get the current row style.

Parameters
Return type

Union[str, Style]

classmethod grid(*headers, padding=0, collapse_padding=True, pad_edge=False, expand=False)[source]

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

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

  • 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: Tuple[int, int, int, int]

Get cell padding.

property row_count: int

Get the current number of rows.