{"id":4291,"library":"treetable","title":"Treetable","description":"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.","status":"active","version":"0.2.6","language":"en","source_language":"en","source_url":"https://github.com/adefossez/treetable","tags":["ascii-table","pretty-print","tree-structure","cli","console-output"],"install":[{"cmd":"pip install treetable","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"treetable","correct":"from treetable import treetable"},{"symbol":"table","correct":"from treetable import table"},{"symbol":"group","correct":"from treetable import group"},{"symbol":"leaf","correct":"from treetable import leaf"}],"quickstart":{"code":"from treetable import table, group, leaf, treetable\n\nmytable = table([\n    group('info', [\n        leaf('name'),\n        leaf('index')\n    ]),\n    group('metrics', align='>', groups=[\n        leaf('speed', '.0f'),\n        leaf('accuracy', '.1%'),\n        leaf('special', '.1%', align='=')\n    ]),\n])\n\nlines = [\n    {'info': {'name': 'bob', 'index': 4}, 'metrics': {'speed': 200, 'accuracy': 0.21, 'special': 0.1}},\n    {'info': {'name': 'alice', 'index': 2}, 'metrics': {'speed': 67, 'accuracy': 0.45, 'special': 4.56}},\n]\n\nprint(treetable(lines, mytable))","lang":"python","description":"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."},"warnings":[{"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.","message":"Be 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All"},{"fix":"Provide a list of custom separator strings via the `separators` argument in the `treetable()` call, for example: `treetable(lines, mytable, separators=['-', ':', '::', '---'])`.","message":"The 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.","severity":"gotcha","affected_versions":"All"},{"fix":"For precise column width control, consider pre-processing your data or using fixed-width string formatting rather than relying solely on `shorten`.","message":"The `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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}