Treetable is a Python helper library designed to pretty-print data in an ASCII table format with a hierarchical, tree-like structure. It enables the creation of complex tables with nested sub-tables, using different separators for each level to enhance readability. The library is currently at version 0.2.6 and appears to be actively maintained.
pip install treetableVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define a nested table structure using `table`, `group`, and `leaf` functions, then render data using the main `treetable` function. It showcases custom alignment and formatting for different data fields.
Always qualify your search queries (e.g., 'python treetable library') and verify the documentation source (adefossez/treetable on GitHub or PyPI) to ensure it's the correct Python package.
Carefully construct your `lines` data to precisely mirror the hierarchical 'key' structure defined in your `mytable` object. Pay attention to nesting and dictionary keys.
Provide a list of custom separator strings via the `separators` argument in the `treetable()` call, for example: `treetable(lines, mytable, separators=['-', ':', '::', '---'])`.
For precise column width control, consider pre-processing your data or using fixed-width string formatting rather than relying solely on `shorten`.
Install the library using pip in your terminal: `pip install treetable`
Import 'Table' and 'SubTable' directly from the 'treetable' package: `from treetable import Table, SubTable`
Ensure that each row of data (list or tuple) contains exactly the same number of elements as there are columns defined for the table. Example: `table = Table(columns=['Col1', 'Col2']); table.add_row(['Value1', 'Value2'])`
Wrap the subtable data within a `treetable.SubTable` object before adding it to the parent table. Example: `subtable_obj = SubTable(columns=['SubCol'], initial_data=[['SubRow']]); table.add_subtable(subtable_obj)`
No dependency data recorded yet.