The Tabulate Extension provides output handling based on the Tabulate library. It’s format is familiar to users of MySQL, Postgres, etc.


  • Tabulate (pip install tabulate)


This extension does not support any configuration settings.


from cement.core import foundation

class MyApp(foundation.CementApp):
    class Meta:
        label = 'myapp'
        extensions = ['tabulate']
        output_handler = 'tabulate'

with MyApp() as app:

    # create a dataset
    headers = ['NAME', 'AGE', 'ADDRESS']
    data = [
        ["Krystin Bartoletti", 47, "PSC 7591, Box 425, APO AP 68379"],
        ["Cris Hegan", 54, "322 Reubin Islands, Leylabury, NC 34388"],
        ["George Champlin", 25, "Unit 6559, Box 124, DPO AA 25518"],

    app.render(data, headers=headers)

Looks like:

| NAME               | AGE | ADDRESS                                 |
| Krystin Bartoletti |  47 | PSC 7591, Box 425, APO AP 68379         |
| Cris Hegan         |  54 | 322 Reubin Islands, Leylabury, NC 34388 |
| George Champlin    |  25 | Unit 6559, Box 124, DPO AA 25518        |
class cement.ext.ext_tabulate.TabulateOutputHandler(*args, **kw)

Bases: cement.core.output.CementOutputHandler

This class implements the IOutput interface. It provides tabularized text output using the Tabulate module. Please see the developer documentation on Output Handling.

Note This extension has an external dependency on tabulate. You must include tabulate in your applications dependencies as Cement explicitly does not include external dependencies for optional extensions.

class Meta

Bases: object

Handler meta-data.

float_format = 'g'

String format to use for float values.

format = 'orgtbl'

Default template format. See the tabulate documentation for all supported template formats.

headers = []

Default headers to use.


alias of IOutput

missing_value = ''

Default replacement for missing value.

numeric_alignment = 'decimal'

Default alignment for numeric columns. See the tabulate documentation for all supported numalign options.

overridable = False

Whether or not to include tabulate as an available to choice to override the output_handler via command line options.

padding = True

Whether or not to pad the output with an extra pre/post ‘n’

string_alignment = 'left'

Default alignment for string columns. See the tabulate documentation for all supported stralign options.

TabulateOutputHandler.render(data, **kw)

Take a data dictionary and render it into a table. Additional keyword arguments are passed directly to tabulate.tabulate.

Required Arguments:

Parameters:data_dict – The data dictionary to render.
Returns:str (the rendered template text)