Introduction

tinytab is a small library for formatting values and rendering small tables, as text or as HTML. It has no dependencies beyond Python itself.

It exists as an example: a small but complete package that shows how to structure, test, and document a Python library. It isn’t published on PyPI.

Installation

Install tinytab from its GitHub repository:

Terminal
pip install git+https://github.com/rich-iannone/example-python-package.git

A first look

tinytab does three things. It formats single values as strings:

from tinytab import fmt_currency

fmt_currency(1234.5)
'$1,234.50'

It builds tables, with a formatter attached to any column:

from tinytab import Table

menu = Table(
    {
        "item": ["coffee", "bagel", "croissant"],
        "price": [3.5, 2.25, 4.0],
    }
)

menu.fmt("price", fmt_currency)
itemprice
coffee$3.50
bagel$2.25
croissant$4.00

And it summarizes sets of numbers:

from tinytab import summarize

summarize([3.5, 2.25, 4.0])
SummaryResult(n=3, mean=3.25, sd=0.9014, min=2.25, max=4)

The rest of this guide takes each of these in turn: