Create pretty tables from headers and rows, perfect for console output.
Project description
Pretty Tables will create uniformly dispersed columns based on the input given and can be scaled to your needs in length of the table or number of columns. The input is automatically validated before returning successfully. Here is a simple sample output:
| ID | Name | Occupation | Employed |
| -- | ------ | ----------------- | -------- |
| 1 | Justin | Software Engineer | True |
| 2 | Misty | Receptionist | False |
| 3 | John | No data | False |
Install
# Install package
pip3 install pretty-tables
# Install locally
make install
# Get Makefile help
make help
Usage
Pretty Tables is simple to use. Pass the generate_table
function an array of headers and a 2 dimensional array of rows (each row must match the length of the headers). Pass an optional empty_cell_placeholder
to change the default behavior or what None
will say in the table.
Pretty Tables will automatically validate the input and convert each item to a string before returning successfully; however, you can pass Pretty Tables any data type within an array. In the following example, we are using integers, booleans, None, and strings:
from pretty_tables import PrettyTables
headers = ['ID', 'Name', 'Occupation', 'Employed']
rows = [
[1, 'Justin', 'Software Engineer', True],
[2, 'Misty', 'Receptionist', False],
[3, 'John', None, False],
]
table = PrettyTables.generate_table(
headers=headers,
rows=rows,
empty_cell_placeholder='No data'
)
print(table)
Colors
You can also color each column differently by using the colors
argument and passing a list of colors from the pretty_tables.TableColors
class that matches the length of the headers list.
Available Colors
- HEADER
- OKBLUE
- OKCYAN
- OKGREEN
- WARNING
- FAIL
- ENDC
- BOLD
- UNDERLINE
Development
# Lint the project
make lint
# Run tests
make test
# Run test coverage
make coverage
Attribution
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pretty_tables-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d1bac09366bf50c2bb974d83c53f3be075e786a265d421ed85c3fa4eba16ac1 |
|
MD5 | 83ceeb049b4f7b98ce190363a9065389 |
|
BLAKE2b-256 | a932dda7347cea65ed8db35db5780d667dc00e7119c8a4920d65abc8e354e724 |