CLI Helpers
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
- breaking Support for Python 2.7 and 3.5 has been removed. Users on these older Python versions must upgrade to Python 3.6 or newer to use `cli-helpers` version 2.x and above.
- gotcha Updating `cli-helpers` may require updating its core tabular formatting dependencies (e.g., `tabulate`, `terminaltables`) to their latest versions to avoid `ImportError` or other compatibility issues. Ensure all related packages are up-to-date.
Install
-
pip install cli-helpers
Imports
- tabular_output
from cli_helpers import tabular_output
- TabularOutputFormatter
from cli_helpers.tabular_output import TabularOutputFormatter
Quickstart
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))