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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hamolicious-cli-table-1.1.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hamolicious_cli_table-1.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file hamolicious-cli-table-1.1.1.tar.gz.

File metadata

  • Download URL: hamolicious-cli-table-1.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for hamolicious-cli-table-1.1.1.tar.gz
Algorithm Hash digest
SHA256 783d4fe08c6e439cf15951caf5431ceebf32410d865a2e73e808bbfb9133926c
MD5 79663f2489a028fc3e7570f504d67c34
BLAKE2b-256 783d7769c9c27b1f250e890fc3310ce08819dadca6dc5ebde423f2f7556faf08

See more details on using hashes here.

File details

Details for the file hamolicious_cli_table-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hamolicious_cli_table-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c532a3a6c3a7ec77b0205279b3559e00ad711d3706e62cb1eb61e390d921128
MD5 c719234cbc9047480eab39f1d3c35286
BLAKE2b-256 654ca317e049ba2bf5d77f040d529e957bf24c86a42dd52941021c1331dccb0e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page