Renderers

class rolumns.renderers.MarkdownRenderer(columns: Columns, mask: Optional[List[str]] = None)[source]

Renders the set of columns columns to an iterable list of strings that make up a Markdown table row-by-row.

All columns will be rendered by default. To specify columns and their order, pass mask and/or call MarkdownRenderer.append().

from rolumns import Columns
from rolumns.renderers import MarkdownRenderer

data = [
    {
        "name": "Robert Pringles",
        "email": "bob@pringles.pop",
    },
    {
        "name": "Daniel Sausage",
        "email": "danny@pringles.pop",
    },
    {
        "name": "Charlie Marmalade",
        "email": "charlie@pringles.pop",
    },
]

columns = Columns()
columns.add("Name", "name")
columns.add("Email", "email")

renderer = MarkdownRenderer(columns)
rows = renderer.render(data)

print(list(rows))
 ['| Name | Email |',
  '| - | - |',
  '| Robert Pringles | bob@pringles.pop |',
  '| Daniel Sausage | danny@pringles.pop |',
  '| Charlie Marmalade | charlie@pringles.pop |']
append(column: str, alignment: Optional[ColumnAlignment] = None) None[source]

Appends a column to the table.

static length(value: str) int[source]

Calculates the displayable width of a string.

static pad(value: str, length: int, align: Optional[ColumnAlignment] = None) str[source]

Pads a string to a displayable width.

render(data: Optional[Any] = None) Iterable[str][source]

Translates data into an iterable list of strings that make up a Markdown table row-by-row.

render_string(data: Optional[Any] = None) str[source]

Translates data into a Markdown table.

class rolumns.renderers.RowsRenderer(columns: Columns, mask: Optional[List[str]] = None)[source]

Renders the set of columns columns to an iterable list of rows.

All columns will be rendered by default. To specify columns and their order, pass mask and/or call RowsRenderer.append().

append(column: str) None[source]

Appends a column to the table.

render(data: Optional[Any] = None) Iterable[List[Any]][source]

Translates data into an iterable list of rows.