pyRestTable

author:

Pete Jemian

version:

2020.0

release:

2020.0.10

published:

Oct 01, 2024

source code documentation

Format a nice table in reST (restructured text).

User Interface

Description

Table

Construct a table in reST

addLabel()

add label for one additional column

addRow()

add list of items for one additional row

setLongtable()

set longtable attribute (LaTeX-only)

setTabularColumns()

set use_tabular_columns & alignment attributes (LaTeX-only)

reST()

render the table in reST format

Table([dd])

Construct a table in reST (no row or column spans).

example_minimal()

minimal example table

example_basic()

basic example table

example_complicated()

complicated example table

class pyRestTable.rest_table.Table(dd={})[source]

Construct a table in reST (no row or column spans).

Parameters:
  • use_tabular_columns (bool) – if True, embed table in Sphinx ‘.. tabularcolumns:: |%s|’ % alignment’ role

  • alignment ([str]) – with use_tabular_columns, each list item is a column format string, as specified by LaTeX tabulary package format: http://sphinx-doc.org/markup/misc.html?highlight=tabularcolumns#directive-tabularcolumns

  • longtable (bool) – with use_tabular_columns, if True, add Sphinx :longtable: directive

  • dd (dict) – dictionary with content for the table

MAIN METHODS

addLabel(text)

add label for one additional column

addRow(list_of_items)

add list of items for one additional row

reST([indentation, fmt])

render the table in reST format

SUPPORTING METHODS

dict_to_table(dd)

Make (or append to) table from dictionary.

setLongtable([state])

Set longtable attribute.

setTabularColumns([state, column_spec])

Set use_tabular_columns & alignment attributes.

plain_table([indentation])

render the table in plain reST format

simple_table([indentation])

render the table in simple reST format

grid_table([indentation])

render the table in grid reST format

list_table([indentation])

render the table in list-table reST format:

html_table([indentation])

render the table in HTML

addLabel(text)[source]

add label for one additional column

Parameters:

text (str) – column label text

Return int:

number of labels

addRow(list_of_items)[source]

add list of items for one additional row

Parameters:

list_of_items ([obj]) – list of items for one complete row

Return int:

number of rows

dict_to_table(dd)[source]

Make (or append to) table from dictionary.

PARAMETERS

dd dict:

Dictionary to create (or append to) table. Keys are the column labels, values are the rows. Empty cells, created if the values are not of equal lengths, will be filled with "" (empty string).

(New in version 2020.0.8)

find_widths()[source]

measure the maximum width of each column, considering possible line breaks in each cell

grid_table(indentation='')[source]

render the table in grid reST format

html_table(indentation='')[source]

render the table in HTML

list_table(indentation='')[source]

render the table in list-table reST format:

See:

http://docutils.sourceforge.net/docs/ref/rst/directives.html

Frozen Delights!

Treat

Quantity

Description

Albatross

2.99

On a stick!

Crunchy Frog

1.49

If we took the bones out, it wouldn’t be crunchy, now would it?

Gannet Ripple

1.99

On a stick!

markdown_table(indentation='')[source]

render the table in GitHub-flavored markdown (not reST) format

see: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables

plain_table(indentation='')[source]

render the table in plain reST format

reST(indentation='', fmt=None)[source]

render the table in reST format

setLongtable(state=True)[source]

Set longtable attribute.

Note

Only used for LaTeX output.

Parameters:

longtable (bool) – True | False

setTabularColumns(state=True, column_spec=None)[source]

Set use_tabular_columns & alignment attributes.

Note

Only used for LaTeX output.

Parameters:
  • state (bool) – True | False

  • column_spec ([str]) – list of column specifications

simple_table(indentation='')[source]

render the table in simple reST format

pyRestTable.rest_table.example_basic()[source]

basic example table

pyRestTable.rest_table.example_complicated()[source]

complicated example table

pyRestTable.rest_table.example_minimal()[source]

minimal example table