API

monotable.HR_ROW
Row containing a horizontal rule to use as a row in cellgrid.
monotable.VR_COL
Vertical rule column for use as a column_tuple with monocol().
monotable.MonoTable
Class to create an aligned and formatted text table from a grid of cells.

Functions

The convenience functions below are the quickest way to generate an Ascii table. They create and configure a temporary instance of the class MonoTable and call a member function.

monotable.mono(headings: Iterable[str] = (), formats: Iterable[str] = (), cellgrid: Iterable[Iterable[Any]] = ((),), title: str = '', *, bordered: bool = False, format_func_map: Optional[Mapping[str, Callable[[Any, str], str]]] = None, guideline_chars: str = '---', indent: str = '') → str

Generate ASCII table from cellgrid.

Parameters:
  • headings – Iterable of strings for each column heading.
  • formats – Iterable of format strings of the form [align_spec][directives][format_spec]. Please see Format directive string syntax.
  • cellgrid – representing table cells.
  • title[align_spec][wrap_spec]string. Text to be aligned and printed above the text table. Please see Title string syntax.
Keyword Arguments:
 
  • bordered – True means generate table with ASCII cell border characters.
  • format_func_map

    Dictionary of format functions keyed by name. name, when used as a format directive in a format string, selects the corresponding function from the dictionary.

    If a key is one of the included format directive function names like ‘boolean’, ‘mformat’, etc. the included format directive function is hidden.

    This value overrides format_func_map in the MonoTable instance that generates the table.

  • guideline_chars – String of 0 to 3 characters to specify top, heading, and bottom guideline appearance. This value overrides guideline_chars in the MonoTable instance that generates the table.
  • indent – String added to the beginning of each line in the text table.
Returns:

The text table as a single string.

Raises:

MonoTableCellError

monotable.monocol(column_tuples: Sequence[Tuple[str, str, Sequence[T_co]]] = (), title: str = '', *, bordered: bool = False, format_func_map: Optional[Mapping[str, Callable[[Any, str], str]]] = None, guideline_chars: str = '---', indent: str = '') → str

Generate ASCII table from column tuples.

Parameters:
  • column_tuples

    List of tuple of (heading string, format string, iterable of cell objects).

    The heading string syntax is described here table() under the parameter headings. The column tuple has a single heading string.

    The format directive string syntax is described here Format directive string syntax. The column tuple has a single format string.

    Iterable of cell objects represent the cells in the column.

  • title[align_spec][wrap_spec]string. Text to be aligned and printed above the text table. Please see Title string syntax.
Keyword Arguments:
 
  • bordered – True means generate table with ASCII cell border characters.
  • format_func_map

    Dictionary of format functions keyed by name. name, when used as a format directive in a format string, selects the corresponding function from the dictionary.

    If a key is one of the included format directive function names like ‘boolean’, ‘mformat’, etc. the included format directive function is hidden.

    This value overrides format_func_map in the MonoTable instance that generates the table.

  • guideline_chars – String of 0 to 3 characters to specify top, heading, and bottom guideline appearance. This value overrides guideline_chars in the MonoTable instance that generates the table.
  • indent – String added to the beginning of each line in the text table.
Returns:

The text table as a single string.

Raises:

MonoTableCellError

monotable.join_strings(multi_line_strings: List[str], *, title: str = '', rsep: str = ' ', valign: int = 10) → str

Join side-by-side multi-line strings preserving vertical alignment.

Parameters:

multi_line_strings – List of strings.

Keyword Arguments:
 
  • title – Text to be aligned and printed above the joined strings. Please see Title string syntax.
  • rsep – Text placed between each line of the multi-line strings on the right hand side. It is not applied to the right-most multi-line string.
  • valign – Alignment used for vertical justification of multi-line strings when the number of lines in the strings differ. Callers should use one of TOP, CENTER_TOP, CENTER_BOTTOM, or BOTTOM defined in monotable.alignment.

Legacy Functions

Since v2.1.0 these functions are superseded by mono() and monocol() above. The details of the function parameters are provided in the class MonoTable docstrings located by following the links below.

monotable.table.table(headings: Iterable[str] = (), formats: Iterable[str] = (), cellgrid: Iterable[Iterable[Any]] = ((), ), title: str = '') → str

Wrapper to monotable.table.MonoTable.table().

monotable.table.bordered_table(headings: Iterable[str] = (), formats: Iterable[str] = (), cellgrid: Iterable[Iterable[Any]] = ((), ), title: str = '') → str

Wrapper to monotable.table.MonoTable.bordered_table().

monotable.table.cotable(column_tuples: Sequence[Tuple[str, str, Sequence[T_co]]] = (), title: str = '') → str

Wrapper to monotable.table.MonoTable.cotable().

monotable.table.cobordered_table(column_tuples: Sequence[Tuple[str, str, Sequence[T_co]]] = (), title: str = '') → str

Wrapper to monotable.table.MonoTable.cobordered_table().

Note

The prefix co in cotable and cobordered_table stands for column oriented.