Skip to main content

Console-Table

Displaying Tables in the console

How To Use

# Import package
from cli_table import Table, align_data_left, align_data_center, align_data_right

# Create some data
data = [
	['First Name', 'Last Name', 'Grade'],
	['Roy', 'Trenneman', 5],
	['Maurice', 'Moss', 1],
	['Jen', 'Barber', 6],
	['Douglas', 'Reynholm', 9],
	['Richmond', 'Avenal', 7],
]

# Create the table
table = Table(
	data,
	alignment=[align_data_left, align_data_left, align_data_right],
	header_alignment=align_data_center,
	header=True,
)

# Sort by specific rows
table.sort_by('Grade')

# Freeze the table
table.freeze()

# Print the table
print(table)

Output:

| First Name | Last Name | Grade |
| Maurice    | Moss      |     1 |
| Roy        | Trenneman |     5 |
| Jen        | Barber    |     6 |
| Richmond   | Avenal    |     7 |
| Douglas    | Reynholm  |     9 |

Arguments

Table()

Creates a table object

Argument Type Default Value Description
data list[list[Any]] 2D array containing the data to be used
margin= int 1 Margin around cells, (how many spaces before and after data)
alignment= Function | list[Function] How to align data, either per column (type list) or globally (type Function)
header_alignment= Function How to align headers
header= bool False Does the data contain a header (0th row is the header)
add_top= bool False Add a top border around the table
add_bottom= bool False Add a bottom border around the table
use_color= bool False Use colorama colors for the table
header_color_bg= str colorama.Back.RESET Header Background Color
header_color_fg= str colorama.Fore.LIGHTBLUE_EX Header Foreground Color
odd_color_bg= str colorama.Back.RESET Odd Numbered Cells Background Color
odd_color_fg= str colorama.Fore.BLUE Odd Numbered Cells Foreground Color
even_color_bg= str colorama.Back.RESET Even Numbered Cells Background Color
even_color_fg= str colorama.Fore.CYAN Even Numbered Cells Foreground Color

Table().is_frozen()

Checks if the table needs to be frozen before printing

Table().sort_by()

Sorts the table by the values of a column

Argument Type Default Value Description
column str | int Which column index(int) or name(str) to sort by
key= None | Callable None Sorting key, takes the entire row, should return a sortable value, bu default, returns the entire cell
reverse= bool False Reverses the sorting algorithm, asc or desc

Table().update_data()

Changes the data that the table has

Argument Type Default Value Description
data list[list[Any]] New data to be used

Table().freeze()

Compiles the given data into a string for quick displaying

Table().display() | print(Table())

Prints the table

Metadata

Release files for hamolicious-cli-table 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hamolicious-cli-table 1.1.1
File Size Uploaded
hamolicious-cli-table-1.1.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hamolicious-cli-table 1.1.1
File Interpreter ABI Platform
hamolicious_cli_table-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / hamolicious-cli-table-1.1.1.tar.gz

Download URL hamolicious-cli-table-1.1.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
783d4fe08c6e439cf15951caf5431ceebf32410d865a2e73e808bbfb9133926c
BLAKE2b-256 checksum
How to use checksums
783d7769c9c27b1f250e890fc3310ce08819dadca6dc5ebde423f2f7556faf08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / hamolicious_cli_table-1.1.1-py3-none-any.whl

Download URL hamolicious_cli_table-1.1.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c532a3a6c3a7ec77b0205279b3559e00ad711d3706e62cb1eb61e390d921128
BLAKE2b-256 checksum
How to use checksums
654ca317e049ba2bf5d77f040d529e957bf24c86a42dd52941021c1331dccb0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page