Columnar

1.4.1 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates the basic usage of the `columnar` function to format a list of lists into a readable table. It shows how to define headers and how to apply the `no_borders` option along with custom column justification.

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)

view raw JSON →