Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pretty-tables

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-tables

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

  • 3.1.0
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc