from tinytab import fmt_currency
fmt_currency(1234.5)'$1,234.50'
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.
Install tinytab from its GitHub repository:
tinytab does three things. It formats single values as strings:
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)| item | price |
|---|---|
| coffee | $3.50 |
| bagel | $2.25 |
| croissant | $4.00 |
And it summarizes sets of numbers:
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: