Skip to main content

Create pretty tables from headers and rows, perfect for console output.

Project description

Pretty Tables

Create pretty tables from headers and rows, perfect for console output.

Build Status Coverage Status PyPi Licence

Showcase

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 and converted to strings 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) and generate a table! 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)

Development

# Lint the project
make lint

# Run tests
make test

# Run test coverage
make coverage

Attribution

Project details


Download files

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

Source Distribution

pretty-tables-1.0.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page