rich.table¶
-
class
rich.table.
Column
(header: RenderableType = '', footer: RenderableType = '', header_style: Union[str, Style] = '', footer_style: Union[str, Style] = '', style: Union[str, Style] = '', justify: JustifyMethod = 'left', overflow: OverflowMethod = 'ellipsis', width: Optional[int] = None, min_width: Optional[int] = None, max_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.
-
copy
() → rich.table.Column[source]¶ Return a copy of this Column.
-
property
flexible
¶ Check if this column is flexible.
Renderable for the footer (typically a string)
- Type
RenderableType
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
-
width
: Optional[int] = None¶ Width of the column, or
None
(default) to auto calculate width.- Type
Optional[int]
-
property
-
class
rich.table.
Row
(style: Optional[Union[str, rich.style.Style]] = None, end_section: bool = False)[source]¶ Information regarding a row.
-
end_section
: bool = False¶ Indicated end of section, which will force a line beneath the row.
-
style
: Optional[Union[str, rich.style.Style]] = None¶ Style to apply to row.
-
-
class
rich.table.
Table
(*headers: Union[rich.table.Column, str], title: Union[str, Text] = None, caption: Union[str, Text] = None, width: int = None, min_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: Optional[Union[str, Style]] = 'table.header', footer_style: Optional[Union[str, Style]] = 'table.footer', 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', highlight: bool = 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). 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 “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: 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, min_width: int = None, max_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, 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”.
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
orTable.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, end_section: bool = False) → 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.
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.
-
property
expand
¶ Setting a non-None self.width implies expand.
-
classmethod
grid
(*headers: Union[rich.table.Column, str], 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
*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
-
property
padding
¶ Get cell padding.
-
property
row_count
¶ Get the current number of rows.