This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

tabletext is a Python library to format (pretty-print) tabular data as text tables. Its goal is to be as simple as possible, while allowing optional customization of the output.

tabletext also comes with a command line utility, table which formats its input into a table and prints it on the standard output.

Installation

tabletext is available on Pypi and can be installed with:

$ pip install tabletext

Overview

Library

tabletext exposes a single function, to_text which in its simplest form takes a list of list (or any sequence of sequences) and format it as a table. The data is assumed to be in row-major order, meaning that the outer sequence’s elements are the rows of the table.

>>> from tabletext import to_text
>>> a = [["Code", "Name"],
         ["AD", "ANDORRA"],
         ["AE", "UNITED ARAB EMIRATES"],
         ["AF", "AFGHANISTAN"],
         ["AG", "ANTIGUA AND BARBUDA"]]
>>> print to_text(a)

will output the following:

┌──────┬──────────────────────┐
│ Code │ Name                 │
├──────┼──────────────────────┤
│ AD   │ ANDORRA              │
├──────┼──────────────────────┤
│ AE   │ UNITED ARAB EMIRATES │
├──────┼──────────────────────┤
│ AF   │ AFGHANISTAN          │
├──────┼──────────────────────┤
│ AG   │ ANTIGUA AND BARBUDA  │
└──────┴──────────────────────┘

You can customize the output with optional arguments:

>>> print to_text(a, header=True, corners="+", hor="-", ver="|",
                  header_corners="+", header_hor="=",
                  header_ver="!", formats=[">", "<"])

will output:

+======+======================+
! Code ! Name                 !
+======+======================+
|   AD | ANDORRA              |
+------+----------------------+
|   AE | UNITED ARAB EMIRATES |
+------+----------------------+
|   AF | AFGHANISTAN          |
+------+----------------------+
|   AG | ANTIGUA AND BARBUDA  |
+------+----------------------+
|   AI | ANGUILLA             |
+------+----------------------+

See the Documentation section for more details about the optional arguments of the to_text function.

Command line utility

The command line utility reads from its input the table, each line representing a row, its entries being separated by \t characters (configurable) and outputs the formatted table to the standard output:

$ df -h | tr -s ' ' \\t | cut -f1-6 | table --header
╒════════════╤══════╤══════╤═══════╤══════╤════════════════╕
│ Filesystem │ Size │ Used │ Avail │ Use% │ Mounted        │
╞════════════╪══════╪══════╪═══════╪══════╪════════════════╡
│ /dev/sda2  │ 25G  │ 14G  │ 9.5G  │ 60%  │ /              │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ dev        │ 3.8G │ 0    │ 3.8G  │ 0%   │ /dev           │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ run        │ 3.8G │ 756K │ 3.8G  │ 1%   │ /run           │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ tmpfs      │ 3.8G │ 1.3M │ 3.8G  │ 1%   │ /dev/shm       │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ tmpfs      │ 3.8G │ 0    │ 3.8G  │ 0%   │ /sys/fs/cgroup │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ /dev/sda1  │ 511M │ 24M  │ 488M  │ 5%   │ /boot          │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ tmpfs      │ 3.8G │ 372M │ 3.5G  │ 10%  │ /tmp           │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ /dev/sda3  │ 15G  │ 9.8G │ 4.2G  │ 71%  │ /home          │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ /dev/sda5  │ 77G  │ 46G  │ 27G   │ 64%  │ /media/data    │
├────────────┼──────┼──────┼───────┼──────┼────────────────┤
│ tmpfs      │ 774M │ 16K  │ 774M  │ 1%   │ /run/user/1000 │
└────────────┴──────┴──────┴───────┴──────┴────────────────┘

The available options can be printed with table --help and closely follow the optional arguments of the library’s to_text function as documented here.

Documentation

The optional arguments of the to_text function are as follows:

Argument Default Description
formats None Format strings for the entries (see below)
padding (1, 1) Left and right padding lengths
corners "┌┬┐├┼┤└┴┘" Characters to use for the corners
hor "─" Horizontal separation character
ver "│" Vertical separation character
header False Wether or not to display the first row as a header row
header_corners "╒╤╕╞╪╡" Characters to use for the header row corners
header_hor "═" Horizontal separation character for the header row
header_ver "│" Vertical separation character for the header row

More about some options:

  • formats can be either a single format string, in which case it will be used for all entries, or a list of format strings, one per column of the table. The format strings must follow Python’s format specification. Note however that you don’t have to specify the width since it is automatically computed. Useful format strings are "<", ">" and "=" for left-aligned, right-aligned and centered columns respectively.
  • corners and header_corners are strings containing the corner characters to be used for rows and the header row respectively. Follow the same order as in the default values. Alternatively, you can specify only one character (that is, a string of length 1) which will be used for all corners.

Release history

0.1 (2014-08-14)

Initial release

Release History

Release History

0.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
tabletext-0.1.tar.gz (6.1 kB) Copy SHA256 Checksum SHA256 Source Aug 14, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting