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 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


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.3.0.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

pretty_tables-1.3.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

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