CLI Helpers

2.12.0 · active · verified Sun Apr 12

CLI Helpers is a Python package that simplifies common tasks in building command-line applications. It serves as a helper library for command-line interfaces, complementing tools like Click and Python Prompt Toolkit by offering simple interfaces for tasks such as pretty-printing tabular data and handling configuration files. The current version is 2.12.0, with ongoing development and updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `cli-helpers` to pretty-print tabular data. It shows both the direct `tabular_output.format_output` function and the `TabularOutputFormatter` class for more advanced formatting options.

from cli_helpers import tabular_output

data = [[1, 'Asgard', True], [2, 'Camelot', False], [3, 'El Dorado', True]]
headers = ['id', 'city', 'visited']

# Format output using the 'simple' display format
output_lines = tabular_output.format_output(iter(data), headers, format_name='simple')
print("\n".join(output_lines))

# Example with a different format using TabularOutputFormatter
from cli_helpers.tabular_output import TabularOutputFormatter
formatter = TabularOutputFormatter()
output_fancy = formatter.format_output(iter(data), headers, format_name='fancy_grid')
print("\n".join(output_fancy))

view raw JSON →