Columnar
Columnar is a Python library for pretty-printing tabular data in a well-formatted columnar output string. It offers features like customizable headers, column justification (left, center, right), and the ability to apply styling patterns using regular expressions. Its primary use case is enhancing the readability of data for command-line interfaces or logs. The current version is 1.4.1, released in December 2021, indicating a stable and mature utility rather than a rapidly evolving project.
Warnings
- gotcha Be aware that this `columnar` library is for pretty-printing text tables, not for in-memory columnar data storage/processing (like Apache Arrow, Polars, or database-related columnar stores). Searching for 'columnar python' often yields results for those other, distinct, technologies.
- breaking The library explicitly states compatibility only with Python 3.6+ due to its reliance on f-strings. Usage with older Python versions will result in syntax errors.
- gotcha When `no_borders=True` is passed to the `columnar` function, the table headers will be automatically converted to all uppercase characters. This is a stylistic side-effect of disabling borders.
- gotcha Passing empty lists for data or headers might lead to unexpected output or error messages. The project history mentions fixes related to error messages for empty input lists.
Install
-
pip install columnar
Imports
- columnar
from columnar import columnar
Quickstart
from columnar import columnar
data = [
['busybox', 'c3c37d5d', 'linuxnode-1', 'Test server.'],
['alpine-python', '6bb77855', 'linuxnode-2', 'The one that runs python.'],
['redis', 'afb648ba', 'linuxnode-3', 'For queues and stuff.']
]
headers = ['Name', 'ID', 'Host', 'Notes']
# Basic table
table_basic = columnar(data, headers=headers)
print('--- Basic Table ---\n')
print(table_basic)
# Table with no borders and custom justification
table_no_borders = columnar(data, headers=headers, no_borders=True, justify=['l', 'c', 'r', 'l'])
print('\n--- No Borders, Custom Justification ---\n')
print(table_no_borders)