Registry / serialization / treetable

treetable

JSON →
library0.2.6pypypi✓ verified 24d ago

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 treetable
INSTALL
IMPORT
SIG · TREETABLE
T
treetable
serializationpythonv0.2.6
Install
1.5s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.004s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.002s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

treetable
from treetable import treetable
table
from treetable import table
group
from treetable import group
leaf
from treetable import leaf

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.

from treetable import table, group, leaf, treetable mytable = table([ group('info', [ leaf('name'), leaf('index') ]), group('metrics', align='>', groups=[ leaf('speed', '.0f'), leaf('accuracy', '.1%'), leaf('special', '.1%', align='=') ]), ]) lines = [ {'info': {'name': 'bob', 'index': 4}, 'metrics': {'speed': 200, 'accuracy': 0.21, 'special': 0.1}}, {'info': {'name': 'alice', 'index': 2}, 'metrics': {'speed': 67, 'accuracy': 0.45, 'special': 4.56}}, ] print(treetable(lines, mytable))
Debug
Known issues
gotchaBe cautious when searching for 'TreeTable' online, as many results pertain to JavaScript/Angular UI components (e.g., PrimeNG, Reactabular) rather than this specific Python library. Ensure your search context is 'python treetable library' to avoid confusion.
fix
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.
affects: All
gotchaThe `treetable` function expects data in a specific format: a list of nested dictionaries where keys match the 'key' arguments defined in your `table`, `group`, and `leaf` structure. Mismatched keys or an incorrect data structure will lead to missing data or errors in the output.
fix
Carefully construct your `lines` data to precisely mirror the hierarchical 'key' structure defined in your `mytable` object. Pay attention to nesting and dictionary keys.
affects: All
gotchaThe library uses default column separators (`[' ', ' | ', ' || ']`). If your table has more than three levels of nesting or you require different visual separation, you must explicitly pass a `separators` argument to the `treetable` function.
fix
Provide a list of custom separator strings via the `separators` argument in the `treetable()` call, for example: `treetable(lines, mytable, separators=['-', ':', '::', '---'])`.
affects: All
gotchaThe `shorten` argument for columns automatically shortens names but will not shorten a display name if it's already shorter than the underlying column's content width, or if shortening would create ambiguity with other columns in the same sub-table. This behavior can be surprising if strict column width control is expected.
fix
For precise column width control, consider pre-processing your data or using fixed-width string formatting rather than relying solely on `shorten`.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'treetable'
The 'treetable' library has not been installed in the Python environment where the script is being executed.
fix
Install the library using pip in your terminal: `pip install treetable`
AttributeError: module 'treetable' has no attribute 'Table'
The 'Table' class is directly exposed from the 'treetable' package, not as an attribute of the imported 'treetable' module object when using a simple `import treetable` statement.
fix
Import 'Table' and 'SubTable' directly from the 'treetable' package: `from treetable import Table, SubTable`
ValueError: Number of columns in row_data (...) does not match number of columns in table (...)
A row of data provided to `add_row()` or `initial_data` has a different number of elements than the number of columns defined for that table.
fix
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'])`
AttributeError: 'list' object has no attribute 'render'
The `add_subtable` method expects an instance of `treetable.SubTable`, but a plain Python list or other non-SubTable object was provided instead.
fix
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)`
Upgrade
Version history
0.2.6latest on PyPI · released Sep 3, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
treetable — pip install treetable · libregistry