Skip to main content

Tabular data formatter with column types/formatting options and other features.

Project description

Format tabular data in various ways with explicitly defined columns that can each have their own expected types, formatting and highlighting.

Features

  • Specify columns with data types / widths, formatting functions, null-value indicators and processing exception indicators.

  • Auto-sizing columns when presented with a full table of data.

  • Ability to format individual rows for output before all data has been gathered.

  • Quick switching of output formats between tabular text, JSON, YAML & delimited fields.

  • Value highlighting rules: by ranges, trends, min/max and others.

Quick Start

# pip install vegetable first
from vegetable import Table

t = Table()
t.column("Supplier")
t.column("Cost", type=float)
t.row(["Convenience store", 12.99])
t.row(["Wholesaler", "10.29"])
t.row(["Internet store", 11.56])
t.row(["Dodgy pub geezer", 5.00])
print(t)

Manual Installation From Repo

$ git clone https://github.com/mousefad/python-vegetable vegetable
$ cd vegetable
$ python -m venv .
$ . bin/activate
$ pip install --upgrade pip
$ pip install .
$ export PYTHONPATH="$PYTHONPATH:$PWD"

To run examples/network_traffic you may also need to pip install click.

Complete Data Mode

Values can be added to a Table() instace directly row-by-row with row(). When __str__() is invoked, the whole table will be formatted and returned. An advantage of this approach is that column widths will be automatically re-sized if needed (for columns where expand=True was used on column creation).

The output format can also be easily switched:

t = Table()
t.column("Name")
t.column("Hobby")
t.row(["'Bob'", "Just having a whale of a time."])
t.row(["Stang, "Monsterism."])
print(t, end="\n\n")
t.formatter = YamlFormat()
print(t)

Line-by-Line Mode

In applications where we want to print data as it is gathered, we can get string values for the table headers, separators and rows with header_str(), separator_str() mast_head() and row_str(…) functions:

t = Table()
t.column("Item Desc")
t.column("Qty", type=int)
print(t.mast_head())
for desc, num in gather_data():
    print(t.row_str([desc, num]))

TODO

  • Better unit test coverage

  • Multi-column sorting

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

vegetable-1.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

vegetable-1.1.0-py2.py3-none-any.whl (15.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file vegetable-1.1.0.tar.gz.

File metadata

  • Download URL: vegetable-1.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for vegetable-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c51f153e06b608bff1d471c2e814d7f9ea8d92697a727541604ce5a54ec2c55c
MD5 34a0aa5c8d2908140cecc344b7de16f4
BLAKE2b-256 5df7344e2d4aef1997225a2c2583bd9362c1a9e9c5d4d844af7c9f2311deb9f1

See more details on using hashes here.

File details

Details for the file vegetable-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: vegetable-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for vegetable-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0aa78158ff41096442009436b7a9263522b7b669943000472e3f575be87d2ab7
MD5 f79d2e67c20de9ac54157c4ae53e7c4a
BLAKE2b-256 c5759936d944fb689012ca82801db19ceada8ec7c3121928b19dc744e95ed33c

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