https://github.com/hamolicious/console-table
Displaying Tables in the console
https://github.com/hamolicious/console-table
console data pypi python table
Last synced: 12 months ago
JSON representation
Displaying Tables in the console
- Host: GitHub
- URL: https://github.com/hamolicious/console-table
- Owner: hamolicious
- License: wtfpl
- Created: 2022-08-20T23:41:02.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-23T13:38:54.000Z (almost 4 years ago)
- Last Synced: 2025-07-05T09:16:49.989Z (12 months ago)
- Topics: console, data, pypi, python, table
- Language: Python
- Homepage: https://pypi.org/project/hamolicious-cli-table/
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Console-Table
Displaying Tables in the console
## How To Use
```python
# 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().freeze()
Compiles the given data into a string for quick displaying
### Table().display() | print(Table())
Prints the table