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 allows for custom formatting making generating Pretty Tables a breeze.

Install

# Install package
pip3 install pretty-tables

# Install locally
just install

Usage

Pretty Tables is simple to use. Create a table by calling pretty_tables.create(), pass a list of headers and a 2 dimensional list of rows (each row must match the length of the headers). Pass an optional empty_cell_placeholder string, colors list, or a truthy index to customize your Pretty 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 the header or row lists. In the following example, we are using integers, booleans, None, and strings:

import pretty_tables

headers = ['ID', 'Name', 'Occupation', 'Employed']
rows = [
    [1, 'Justin', 'Software Engineer', True],
    [2, 'Misty', 'Receptionist', False],
    [3, 'John', None, False],
]

# Add optional custom colors to each column
colors = [
    pretty_tables.Colors.red,
    pretty_tables.Colors.green,
    pretty_tables.Colors.blue,
    pretty_tables.Colors.purple,
]

# Generate the pretty table output
table = pretty_tables.create(
    headers=headers,
    rows=rows,
    empty_cell_placeholder='No data',  # Optional: override the default `None` with a custom string
    colors=colors,  # Optional: mutually exclusive with `truthy`
    # truthy=3,  # Optional: integer of the column you want to check for truthy values on, mutually exclusive with `colors`
)

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.Colors class. The input list must match the length of the headers list.

  • black
  • blue
  • cyan
  • green
  • purple
  • red
  • white
  • yellow
  • bold
  • reset (resets all text formatting)
  • underline
  • none (acts like reset, used instead of passing None as a color)

Development

# Get a comprehensive list of development tools
just --list

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-3.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

pretty_tables-3.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pretty-tables-3.1.0.tar.gz.

File metadata

  • Download URL: pretty-tables-3.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pretty-tables-3.1.0.tar.gz
Algorithm Hash digest
SHA256 c95ee4f78b4fce96718bdb086d8f0c6d5203955b85102e952ae611ad601c4f7a
MD5 8a488fad59ffcc5e77a1aac9cd41eb74
BLAKE2b-256 219868fd23374ea746b80fe06f6eaad805c9d21f003416ae2696441bf5996bcb

See more details on using hashes here.

File details

Details for the file pretty_tables-3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pretty_tables-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45a714f39e669ff554f32e4a87417dd14ca33481e40ea02be613679241768741
MD5 6dd2aac6e54041548b20c2ce485f2d00
BLAKE2b-256 7a32fbec49bdd9be339103843529b9c1c78a4467ad0616634f56e7e06a239ec6

See more details on using hashes here.

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