This page is the complete API reference for rich.table.Table and its associated types. It covers the Table class constructor, all public methods, the Column dataclass, the Row dataclass, and the internal _Cell type. For a conceptual overview of how tables work and usage examples, see Tables. For information about box drawing styles, see Styles and Colors.
All primary types are defined in rich/table.py
Class and type diagram:
Sources: rich/table.py38-150
Table ClassFile: rich/table.py153
Table is the main renderable. It implements JupyterMixin, __rich_console__, and __rich_measure__.
Table(*headers, title, caption, width, min_width, box, safe_box, padding,
collapse_padding, pad_edge, expand, show_header, show_footer,
show_edge, show_lines, leading, style, row_styles, header_style,
footer_style, border_style, title_style, caption_style,
title_justify, caption_justify, highlight)
| Parameter | Type | Default | Description |
|---|---|---|---|
*headers | Union[Column, str] | — | Column headers passed positionally. Strings produce a default Column; Column instances are used directly. |
title | Optional[TextType] | None | Text rendered above the table. |
caption | Optional[TextType] | None | Text rendered below the table. |
width | Optional[int] | None | Fixed total width in characters. Setting this implies expand=True. |
min_width | Optional[int] | None | Minimum total width. |
box | Optional[box.Box] | box.HEAVY_HEAD | Box drawing style. None removes all box characters. |
safe_box | Optional[bool] | None | If True, replaces box characters unsafe on Windows legacy terminals. |
padding | PaddingDimensions | (0, 1) | Cell padding (CSS-style: 1, 2, or 4 ints). |
collapse_padding | bool | False | Merge adjacent padding between cells. |
pad_edge | bool | True | Apply padding to leftmost and rightmost columns. |
expand | bool | False | Stretch table to fill available width. |
show_header | bool | True | Render the header row. |
show_footer | bool | False | Render the footer row. |
show_edge | bool | True | Render the outer border. |
show_lines | bool | False | Draw horizontal lines between every data row. |
leading | int | 0 | Blank lines between rows. Takes precedence over show_lines. |
style | StyleType | "none" | Default style applied to the entire table. |
row_styles | Optional[Iterable[StyleType]] | None | Alternating row styles applied in order. |
header_style | Optional[StyleType] | "table.header" | Style for the header row. |
footer_style | Optional[StyleType] | "table.footer" | Style for the footer row. |
border_style | Optional[StyleType] | None | Style applied to box-drawing characters. |
title_style | Optional[StyleType] | None | Style for the title text. Falls back to "table.title". |
caption_style | Optional[StyleType] | None | Style for the caption text. Falls back to "table.caption". |
title_justify | JustifyMethod | "center" | Justification for the title. |
caption_justify | JustifyMethod | "center" | Justification for the caption. |
highlight | bool | False | Apply the console highlighter to string cell contents. |
Sources: rich/table.py153-251
grid()Table.grid(*headers, padding=0, collapse_padding=True,
pad_edge=False, expand=False) -> Table
Factory that returns a Table pre-configured with no box, no header, no footer, and no edge — suitable for simple grid layouts. Internally sets box=None, show_header=False, show_footer=False, show_edge=False.
| Parameter | Type | Default |
|---|---|---|
*headers | Union[Column, str] | — |
padding | PaddingDimensions | 0 |
collapse_padding | bool | True |
pad_edge | bool | False |
expand | bool | False |
Note:
Columns(the multi-column layout renderable) usesTable.grid()internally as its layout engine. See Trees and Layout.
Sources: rich/table.py252-283 rich/columns.py119
| Property | Type | Description |
|---|---|---|
expand | bool | True if _expand is True or width is not None. Setting this sets _expand. |
padding | Tuple[int, int, int, int] | Unpacked 4-tuple (top, right, bottom, left). Setter accepts any PaddingDimensions. |
row_count | int | Number of data rows (excludes header and footer). |
Sources: rich/table.py285-308 rich/table.py353-362
add_column()Table.add_column(header="", footer="", *, header_style=None,
highlight=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)
Appends a new Column to self.columns.
| Parameter | Type | Default | Description |
|---|---|---|---|
header | RenderableType | "" | Header cell content. |
footer | RenderableType | "" | Footer cell content. |
header_style | Optional[StyleType] | None | Style for the header cell. None inherits from the table. |
highlight | Optional[bool] | None | Apply highlighter to cell strings. None inherits Table.highlight. |
footer_style | Optional[StyleType] | None | Style for the footer cell. |
style | Optional[StyleType] | None | Style for all data cells in the column. |
justify | JustifyMethod | "left" | "left", "center", "right", or "full". |
vertical | VerticalAlignMethod | "top" | "top", "middle", or "bottom". |
overflow | OverflowMethod | "ellipsis" | "crop", "fold", or "ellipsis". |
width | Optional[int] | None | Fixed character width. None means auto-fit. |
min_width | Optional[int] | None | Minimum character width. |
max_width | Optional[int] | None | Maximum character width. |
ratio | Optional[int] | None | Flex ratio for width distribution (requires expand=True or a fixed width). |
no_wrap | bool | False | Prevent text wrapping in this column. |
Sources: rich/table.py364-420
add_row()Table.add_row(*renderables, style=None, end_section=False)
Appends a Row and distributes cell content to Column._cells.
| Parameter | Type | Default | Description |
|---|---|---|---|
*renderables | Optional[RenderableType] | — | One value per column. None produces an empty cell. Extra values beyond the column count create new auto-columns. |
style | Optional[StyleType] | None | Style applied to the entire row. |
end_section | bool | False | Draw a section separator line after this row. |
Raises: errors.NotRenderableError if a cell value is not renderable and not None.
If fewer renderables are supplied than columns, missing cells are filled with "". If more renderables are supplied than columns, new Column objects are created automatically (with highlight=self.highlight).
Sources: rich/table.py422-467
add_section()Table.add_section()
Sets end_section=True on the last row, causing a separator line to be drawn after it. Has no effect if there are no rows yet.
Sources: rich/table.py469-473
get_row_style()Table.get_row_style(console: Console, index: int) -> StyleType
Combines the cycling row_styles entry (by index % len(row_styles)) with the per-row Row.style. Returns the combined Style.
Sources: rich/table.py310-318
__rich_console__(console, options) — rich/table.py475-521
Implements the Rich renderable protocol. Yields Segment objects. The method:
_calculate_column_widths()._render().__rich_measure__(console, options) — rich/table.py320-351
Implements the Rich measurement protocol. Returns a Measurement(minimum, maximum) based on the sum of column measurements plus border overhead, then clamped to self.min_width.
Sources: rich/table.py320-351 rich/table.py475-521
These are not part of the public API but are documented for completeness.
| Method | Description |
|---|---|
_calculate_column_widths(console, options) | Returns a List[int] of pixel widths per column including padding. Handles expand, ratio columns, over-width collapse, and min_width enforcement. rich/table.py523-586 |
_collapse_widths(widths, wrapable, max_width) | Class method. Iteratively reduces the widest wrappable columns until the total fits within max_width. rich/table.py588-625 |
_get_cells(console, column_index, column) | Generator yielding _Cell tuples for all cells in a column (header, data, footer), with padding applied. rich/table.py627-698 |
_get_padding_width(column_index) | Returns the horizontal padding width for a column, accounting for collapse_padding and pad_edge. rich/table.py700-714 |
_measure_column(console, options, column) | Returns a Measurement for a column by measuring all its cells. For fixed-width columns returns Measurement(width, width). rich/table.py716-753 |
_render(console, options, widths) | Core rendering generator. Iterates row cells, aligns them vertically, and interleaves box segments. rich/table.py755 |
Sources: rich/table.py523-753
Column DataclassFile: rich/table.py38-128
Column is a @dataclass that describes a single column. It is both constructed directly and returned by add_column().
| Field | Type | Default | Description |
|---|---|---|---|
header | RenderableType | "" | Header cell content. |
footer | RenderableType | "" | Footer cell content. |
header_style | StyleType | "" | Style applied to the header cell. |
footer_style | StyleType | "" | Style applied to the footer cell. |
style | StyleType | "" | Style applied to all data cells. |
justify | JustifyMethod | "left" | Horizontal text alignment. |
vertical | VerticalAlignMethod | "top" | Vertical alignment. |
overflow | OverflowMethod | "ellipsis" | Overflow handling. |
width | Optional[int] | None | Fixed width in characters. |
min_width | Optional[int] | None | Minimum width in characters. |
max_width | Optional[int] | None | Maximum width in characters. |
ratio | Optional[int] | None | Flex ratio (used with expand). |
no_wrap | bool | False | Disable text wrapping. |
highlight | bool | False | Apply highlighter to string cells. |
_index | int | 0 | Position within Table.columns (set by Table). |
_cells | List[RenderableType] | [] | Internal list of cell renderables (not set by user). |
| Name | Description |
|---|---|
cells | Property. Yields all data cell renderables from _cells (excludes header and footer). |
flexible | Property. Returns True if ratio is not None. |
copy() | Returns a shallow copy with _cells reset to []. |
Sources: rich/table.py38-128
Row DataclassFile: rich/table.py131-139
Row is a @dataclass storing per-row metadata. It is created by add_row() and stored in Table.rows.
| Field | Type | Default | Description |
|---|---|---|---|
style | Optional[StyleType] | None | Style to apply to this row. Combined with cycling row_styles. |
end_section | bool | False | If True, draw a section separator after this row. |
Sources: rich/table.py131-139
_Cell NamedTupleFile: rich/table.py142-150
An internal type used during rendering. Not part of the public API.
| Field | Type | Description |
|---|---|---|
style | StyleType | Resolved style for the cell. |
renderable | RenderableType | Cell content (possibly wrapped in Padding). |
vertical | VerticalAlignMethod | Vertical alignment for this specific cell. |
Sources: rich/table.py142-150
The following diagram traces how a Table moves through the rendering system to produce terminal output.
Table rendering data flow:
Sources: rich/table.py320-586 rich/table.py755
Understanding how widths are distributed is important when using ratio, width, min_width, and max_width together.
Column width resolution:
width are never collapsed.no_wrap=True are not eligible for collapsing.ratio columns only participate in width distribution when expand is True or a fixed width is set on the Table.Sources: rich/table.py523-586 rich/table.py588-625
Styles are combined additively at render time. The effective style for a data cell is:
table.style
+ table.border_style (for box characters)
+ table.row_styles[i % n] (cycling, for data rows)
+ Row.style (per-row override)
+ Column.style (per-column base)
For header cells:
table.header_style + Column.header_style
For footer cells:
table.footer_style + Column.footer_style
Sources: rich/table.py667-698 rich/table.py755-820
| Type | Module | Role |
|---|---|---|
box.Box | rich/box.py | Box-drawing character set used for borders. |
PaddingDimensions | rich/padding.py | Union of int, Tuple[int], Tuple[int,int], Tuple[int,int,int,int]. |
Padding | rich/padding.py | Wraps a renderable with space on each side; used internally in _get_cells(). |
Measurement | rich/measure.py | NamedTuple(minimum, maximum) returned by __rich_measure__. |
JustifyMethod | rich/console.py | Literal "left", "center", "right", "full". |
VerticalAlignMethod | rich/align.py | Literal "top", "middle", "bottom". |
OverflowMethod | rich/console.py | Literal "crop", "fold", "ellipsis". |
StyleType | rich/style.py | Union[str, Style]. |
TextType | rich/text.py | Union[str, Text]. |
Sources: rich/table.py1-35 rich/padding.py16 rich/measure.py11-17
| Exception | Raised by | Condition |
|---|---|---|
errors.NotRenderableError | Table.add_row() | A cell value is neither None, a str, nor an object implementing the Rich renderable protocol. |
Sources: rich/table.py463-466
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.