| Description: | A table formatter class with support for a variety of outputs. | 
| Latest Version: | 2021 | 
| Source Code: | src/ | 
| Architecture: | 
 | 
| Dependencies: | 
 | 
| Build Dependencies: | 
 | 
| Arch Repositories: | 
 | 
| AUR Page: | python3-tabulator | 
| Arch Forum Thread: | 151526 | 
| Tags: | 
Tabulator is a table formatter class that can output tables in a variety of formats. I wrote it because I found myself rewriting code to align tables far too often.
I will add output formats as I need them, but feel free to submit/suggest new ones or improvements on existing ones.
See the TODO list below to see what else I have in mind.
The API is relatively stable but I guarantee nothing. Keep a local copy and include that in your projects if you need to be sure.
#!/usr/bin/env python3 """ This is quick example of how to work with Tabulator. """ from Tabulator import Tabulator # The first row optionally contains the headers. rows = [('Dec', 'Bin', 'Oct', 'Hex')] # Collect some data in the rows. for i in range(20): rows.append((i, bin(i)[2:], oct(i)[2:], hex(i)[2:])) # To indicate that the first row contains headers, a header alignment parameter # must be passed. tab = Tabulator(rows, headers=('c',), cols=('r',)) print(tab.to_box_table())
┌───┬─────┬───┬───┐
│Dec│ Bin │Oct│Hex│
├───┼─────┼───┼───┤
│  0│    0│  0│  0│
│  1│    1│  1│  1│
│  2│   10│  2│  2│
│  3│   11│  3│  3│
│  4│  100│  4│  4│
│  5│  101│  5│  5│
│  6│  110│  6│  6│
│  7│  111│  7│  7│
│  8│ 1000│ 10│  8│
│  9│ 1001│ 11│  9│
│ 10│ 1010│ 12│  a│
│ 11│ 1011│ 13│  b│
│ 12│ 1100│ 14│  c│
│ 13│ 1101│ 15│  d│
│ 14│ 1110│ 16│  e│
│ 15│ 1111│ 17│  f│
│ 16│10000│ 20│ 10│
│ 17│10001│ 21│ 11│
│ 18│10010│ 22│ 12│
│ 19│10011│ 23│ 13│
└───┴─────┴───┴───┘If this doesn’t align in the browser, copy it and paste it into a code editor, or look at the page source.
The following table was generated by python3-nist using Tabulator. Note the different alignments in each column, including decimal alignment.
Z   Symbol Standard Weight Uncertainty
--- ------ --------------- -----------
  1  H         1.00794     ±0.00007
  2  He        4.002602    ±0.000002
  3  Li        6.941       ±0.002
  4  Be        9.012182    ±0.000003
  5  B        10.811       ±0.007
  6  C        12.0107      ±0.0008
  7  N        14.0067      ±0.0002
  8  O        15.9994      ±0.0003
  9  F        18.9984032   ±0.0000005
 10  Ne       20.1797      ±0.0006
 11  Na       22.98976928  ±0.00000002
 12  Mg       24.3050      ±0.0006
 13  Al       26.9815386   ±0.0000008
 14  Si       28.0855      ±0.0003
 15  P        30.973762    ±0.000002
 16  S        32.065       ±0.005
 17  Cl       35.453       ±0.002
 18  Ar       39.948       ±0.001
 19  K        39.0983      ±0.0001
 20  Ca       40.078       ±0.004
 21  Sc       44.955912    ±0.000006
 22  Ti       47.867       ±0.001
 23  V        50.9415      ±0.0001
 24  Cr       51.9961      ±0.0006
 25  Mn       54.938045    ±0.000005
 26  Fe       55.845       ±0.002
 27  Co       58.933195    ±0.000005
 28  Ni       58.6934      ±0.0004
 29  Cu       63.546       ±0.003
 30  Zn       65.38        ±0.02
 31  Ga       69.723       ±0.001
 32  Ge       72.64        ±0.01
 33  As       74.92160     ±0.00002
 34  Se       78.96        ±0.03
 35  Br       79.904       ±0.001
 36  Kr       83.798       ±0.002
 37  Rb       85.4678      ±0.0003
 38  Sr       87.62        ±0.01
 39  Y        88.90585     ±0.00002
 40  Zr       91.224       ±0.002
 41  Nb       92.90638     ±0.00002
 42  Mo       95.96        ±0.02
 43  Tc       98
 44  Ru      101.07        ±0.02
 45  Rh      102.90550     ±0.00002
 46  Pd      106.42        ±0.01
 47  Ag      107.8682      ±0.0002
 48  Cd      112.411       ±0.008
 49  In      114.818       ±0.003
 50  Sn      118.710       ±0.007
 51  Sb      121.760       ±0.001
 52  Te      127.60        ±0.03
 53  I       126.90447     ±0.00003
 54  Xe      131.293       ±0.006
 55  Cs      132.9054519   ±0.0000002
 56  Ba      137.327       ±0.007
 57  La      138.90547     ±0.00007
 58  Ce      140.116       ±0.001
 59  Pr      140.90765     ±0.00002
 60  Nd      144.242       ±0.003
 61  Pm      145
 62  Sm      150.36        ±0.02
 63  Eu      151.964       ±0.001
 64  Gd      157.25        ±0.03
 65  Tb      158.92535     ±0.00002
 66  Dy      162.500       ±0.001
 67  Ho      164.93032     ±0.00002
 68  Er      167.259       ±0.003
 69  Tm      168.93421     ±0.00002
 70  Yb      173.054       ±0.005
 71  Lu      174.9668      ±0.0001
 72  Hf      178.49        ±0.02
 73  Ta      180.94788     ±0.00002
 74  W       183.84        ±0.01
 75  Re      186.207       ±0.001
 76  Os      190.23        ±0.03
 77  Ir      192.217       ±0.003
 78  Pt      195.084       ±0.009
 79  Au      196.966569    ±0.000004
 80  Hg      200.59        ±0.02
 81  Tl      204.3833      ±0.0002
 82  Pb      207.2         ±0.1
 83  Bi      208.98040     ±0.00001
 84  Po      209
 85  At      210
 86  Rn      222
 87  Fr      223
 88  Ra      226
 89  Ac      227
 90  Th      232.03806     ±0.00002
 91  Pa      231.03588     ±0.00002
 92  U       238.02891     ±0.00003
 93  Np      237
 94  Pu      244
 95  Am      243
 96  Cm      247
 97  Bk      247
 98  Cf      251
 99  Es      252
100  Fm      257
101  Md      258
102  No      259
103  Lr      262
104  Rf      265
105  Db      268
106  Sg      271
107  Bh      272
108  Hs      270
109  Mt      276
110  Ds      281
111  Rg      280
112  Cn      285
113  Uut     284
114  Uuq     289
115  Uup     288
116  Uuh     293
117  Uus     292
118  Uuo     294Here’s the same table in Pandoc’s markdown format:
+---+------+---------------+-----------+
|Z  |Symbol|Standard Weight|Uncertainty|
+===+======+===============+===========+
|  1| H    |    1.00794    |±0.00007   |
+---+------+---------------+-----------+
|  2| He   |    4.002602   |±0.000002  |
+---+------+---------------+-----------+
|  3| Li   |    6.941      |±0.002     |
+---+------+---------------+-----------+
|  4| Be   |    9.012182   |±0.000003  |
+---+------+---------------+-----------+
|  5| B    |   10.811      |±0.007     |
+---+------+---------------+-----------+
|  6| C    |   12.0107     |±0.0008    |
+---+------+---------------+-----------+
|  7| N    |   14.0067     |±0.0002    |
+---+------+---------------+-----------+
|  8| O    |   15.9994     |±0.0003    |
+---+------+---------------+-----------+
|  9| F    |   18.9984032  |±0.0000005 |
+---+------+---------------+-----------+
| 10| Ne   |   20.1797     |±0.0006    |
+---+------+---------------+-----------+
| 11| Na   |   22.98976928 |±0.00000002|
+---+------+---------------+-----------+
| 12| Mg   |   24.3050     |±0.0006    |
+---+------+---------------+-----------+
| 13| Al   |   26.9815386  |±0.0000008 |
+---+------+---------------+-----------+
| 14| Si   |   28.0855     |±0.0003    |
+---+------+---------------+-----------+
| 15| P    |   30.973762   |±0.000002  |
+---+------+---------------+-----------+
| 16| S    |   32.065      |±0.005     |
+---+------+---------------+-----------+
| 17| Cl   |   35.453      |±0.002     |
+---+------+---------------+-----------+
| 18| Ar   |   39.948      |±0.001     |
+---+------+---------------+-----------+
| 19| K    |   39.0983     |±0.0001    |
+---+------+---------------+-----------+
| 20| Ca   |   40.078      |±0.004     |
+---+------+---------------+-----------+
| 21| Sc   |   44.955912   |±0.000006  |
+---+------+---------------+-----------+
| 22| Ti   |   47.867      |±0.001     |
+---+------+---------------+-----------+
| 23| V    |   50.9415     |±0.0001    |
+---+------+---------------+-----------+
| 24| Cr   |   51.9961     |±0.0006    |
+---+------+---------------+-----------+
| 25| Mn   |   54.938045   |±0.000005  |
+---+------+---------------+-----------+
| 26| Fe   |   55.845      |±0.002     |
+---+------+---------------+-----------+
| 27| Co   |   58.933195   |±0.000005  |
+---+------+---------------+-----------+
| 28| Ni   |   58.6934     |±0.0004    |
+---+------+---------------+-----------+
| 29| Cu   |   63.546      |±0.003     |
+---+------+---------------+-----------+
| 30| Zn   |   65.38       |±0.02      |
+---+------+---------------+-----------+
| 31| Ga   |   69.723      |±0.001     |
+---+------+---------------+-----------+
| 32| Ge   |   72.64       |±0.01      |
+---+------+---------------+-----------+
| 33| As   |   74.92160    |±0.00002   |
+---+------+---------------+-----------+
| 34| Se   |   78.96       |±0.03      |
+---+------+---------------+-----------+
| 35| Br   |   79.904      |±0.001     |
+---+------+---------------+-----------+
| 36| Kr   |   83.798      |±0.002     |
+---+------+---------------+-----------+
| 37| Rb   |   85.4678     |±0.0003    |
+---+------+---------------+-----------+
| 38| Sr   |   87.62       |±0.01      |
+---+------+---------------+-----------+
| 39| Y    |   88.90585    |±0.00002   |
+---+------+---------------+-----------+
| 40| Zr   |   91.224      |±0.002     |
+---+------+---------------+-----------+
| 41| Nb   |   92.90638    |±0.00002   |
+---+------+---------------+-----------+
| 42| Mo   |   95.96       |±0.02      |
+---+------+---------------+-----------+
| 43| Tc   |   98          |           |
+---+------+---------------+-----------+
| 44| Ru   |  101.07       |±0.02      |
+---+------+---------------+-----------+
| 45| Rh   |  102.90550    |±0.00002   |
+---+------+---------------+-----------+
| 46| Pd   |  106.42       |±0.01      |
+---+------+---------------+-----------+
| 47| Ag   |  107.8682     |±0.0002    |
+---+------+---------------+-----------+
| 48| Cd   |  112.411      |±0.008     |
+---+------+---------------+-----------+
| 49| In   |  114.818      |±0.003     |
+---+------+---------------+-----------+
| 50| Sn   |  118.710      |±0.007     |
+---+------+---------------+-----------+
| 51| Sb   |  121.760      |±0.001     |
+---+------+---------------+-----------+
| 52| Te   |  127.60       |±0.03      |
+---+------+---------------+-----------+
| 53| I    |  126.90447    |±0.00003   |
+---+------+---------------+-----------+
| 54| Xe   |  131.293      |±0.006     |
+---+------+---------------+-----------+
| 55| Cs   |  132.9054519  |±0.0000002 |
+---+------+---------------+-----------+
| 56| Ba   |  137.327      |±0.007     |
+---+------+---------------+-----------+
| 57| La   |  138.90547    |±0.00007   |
+---+------+---------------+-----------+
| 58| Ce   |  140.116      |±0.001     |
+---+------+---------------+-----------+
| 59| Pr   |  140.90765    |±0.00002   |
+---+------+---------------+-----------+
| 60| Nd   |  144.242      |±0.003     |
+---+------+---------------+-----------+
| 61| Pm   |  145          |           |
+---+------+---------------+-----------+
| 62| Sm   |  150.36       |±0.02      |
+---+------+---------------+-----------+
| 63| Eu   |  151.964      |±0.001     |
+---+------+---------------+-----------+
| 64| Gd   |  157.25       |±0.03      |
+---+------+---------------+-----------+
| 65| Tb   |  158.92535    |±0.00002   |
+---+------+---------------+-----------+
| 66| Dy   |  162.500      |±0.001     |
+---+------+---------------+-----------+
| 67| Ho   |  164.93032    |±0.00002   |
+---+------+---------------+-----------+
| 68| Er   |  167.259      |±0.003     |
+---+------+---------------+-----------+
| 69| Tm   |  168.93421    |±0.00002   |
+---+------+---------------+-----------+
| 70| Yb   |  173.054      |±0.005     |
+---+------+---------------+-----------+
| 71| Lu   |  174.9668     |±0.0001    |
+---+------+---------------+-----------+
| 72| Hf   |  178.49       |±0.02      |
+---+------+---------------+-----------+
| 73| Ta   |  180.94788    |±0.00002   |
+---+------+---------------+-----------+
| 74| W    |  183.84       |±0.01      |
+---+------+---------------+-----------+
| 75| Re   |  186.207      |±0.001     |
+---+------+---------------+-----------+
| 76| Os   |  190.23       |±0.03      |
+---+------+---------------+-----------+
| 77| Ir   |  192.217      |±0.003     |
+---+------+---------------+-----------+
| 78| Pt   |  195.084      |±0.009     |
+---+------+---------------+-----------+
| 79| Au   |  196.966569   |±0.000004  |
+---+------+---------------+-----------+
| 80| Hg   |  200.59       |±0.02      |
+---+------+---------------+-----------+
| 81| Tl   |  204.3833     |±0.0002    |
+---+------+---------------+-----------+
| 82| Pb   |  207.2        |±0.1       |
+---+------+---------------+-----------+
| 83| Bi   |  208.98040    |±0.00001   |
+---+------+---------------+-----------+
| 84| Po   |  209          |           |
+---+------+---------------+-----------+
| 85| At   |  210          |           |
+---+------+---------------+-----------+
| 86| Rn   |  222          |           |
+---+------+---------------+-----------+
| 87| Fr   |  223          |           |
+---+------+---------------+-----------+
| 88| Ra   |  226          |           |
+---+------+---------------+-----------+
| 89| Ac   |  227          |           |
+---+------+---------------+-----------+
| 90| Th   |  232.03806    |±0.00002   |
+---+------+---------------+-----------+
| 91| Pa   |  231.03588    |±0.00002   |
+---+------+---------------+-----------+
| 92| U    |  238.02891    |±0.00003   |
+---+------+---------------+-----------+
| 93| Np   |  237          |           |
+---+------+---------------+-----------+
| 94| Pu   |  244          |           |
+---+------+---------------+-----------+
| 95| Am   |  243          |           |
+---+------+---------------+-----------+
| 96| Cm   |  247          |           |
+---+------+---------------+-----------+
| 97| Bk   |  247          |           |
+---+------+---------------+-----------+
| 98| Cf   |  251          |           |
+---+------+---------------+-----------+
| 99| Es   |  252          |           |
+---+------+---------------+-----------+
|100| Fm   |  257          |           |
+---+------+---------------+-----------+
|101| Md   |  258          |           |
+---+------+---------------+-----------+
|102| No   |  259          |           |
+---+------+---------------+-----------+
|103| Lr   |  262          |           |
+---+------+---------------+-----------+
|104| Rf   |  265          |           |
+---+------+---------------+-----------+
|105| Db   |  268          |           |
+---+------+---------------+-----------+
|106| Sg   |  271          |           |
+---+------+---------------+-----------+
|107| Bh   |  272          |           |
+---+------+---------------+-----------+
|108| Hs   |  270          |           |
+---+------+---------------+-----------+
|109| Mt   |  276          |           |
+---+------+---------------+-----------+
|110| Ds   |  281          |           |
+---+------+---------------+-----------+
|111| Rg   |  280          |           |
+---+------+---------------+-----------+
|112| Cn   |  285          |           |
+---+------+---------------+-----------+
|113| Uut  |  284          |           |
+---+------+---------------+-----------+
|114| Uuq  |  289          |           |
+---+------+---------------+-----------+
|115| Uup  |  288          |           |
+---+------+---------------+-----------+
|116| Uuh  |  293          |           |
+---+------+---------------+-----------+
|117| Uus  |  292          |           |
+---+------+---------------+-----------+
|118| Uuo  |  294          |           |
+---+------+---------------+-----------+and finally the result of inserting it directly into the markdown input for this page:
| Z | Symbol | Standard Weight | Uncertainty | 
|---|---|---|---|
| 1 | H | 1.00794 | ±0.00007 | 
| 2 | He | 4.002602 | ±0.000002 | 
| 3 | Li | 6.941 | ±0.002 | 
| 4 | Be | 9.012182 | ±0.000003 | 
| 5 | B | 10.811 | ±0.007 | 
| 6 | C | 12.0107 | ±0.0008 | 
| 7 | N | 14.0067 | ±0.0002 | 
| 8 | O | 15.9994 | ±0.0003 | 
| 9 | F | 18.9984032 | ±0.0000005 | 
| 10 | Ne | 20.1797 | ±0.0006 | 
| 11 | Na | 22.98976928 | ±0.00000002 | 
| 12 | Mg | 24.3050 | ±0.0006 | 
| 13 | Al | 26.9815386 | ±0.0000008 | 
| 14 | Si | 28.0855 | ±0.0003 | 
| 15 | P | 30.973762 | ±0.000002 | 
| 16 | S | 32.065 | ±0.005 | 
| 17 | Cl | 35.453 | ±0.002 | 
| 18 | Ar | 39.948 | ±0.001 | 
| 19 | K | 39.0983 | ±0.0001 | 
| 20 | Ca | 40.078 | ±0.004 | 
| 21 | Sc | 44.955912 | ±0.000006 | 
| 22 | Ti | 47.867 | ±0.001 | 
| 23 | V | 50.9415 | ±0.0001 | 
| 24 | Cr | 51.9961 | ±0.0006 | 
| 25 | Mn | 54.938045 | ±0.000005 | 
| 26 | Fe | 55.845 | ±0.002 | 
| 27 | Co | 58.933195 | ±0.000005 | 
| 28 | Ni | 58.6934 | ±0.0004 | 
| 29 | Cu | 63.546 | ±0.003 | 
| 30 | Zn | 65.38 | ±0.02 | 
| 31 | Ga | 69.723 | ±0.001 | 
| 32 | Ge | 72.64 | ±0.01 | 
| 33 | As | 74.92160 | ±0.00002 | 
| 34 | Se | 78.96 | ±0.03 | 
| 35 | Br | 79.904 | ±0.001 | 
| 36 | Kr | 83.798 | ±0.002 | 
| 37 | Rb | 85.4678 | ±0.0003 | 
| 38 | Sr | 87.62 | ±0.01 | 
| 39 | Y | 88.90585 | ±0.00002 | 
| 40 | Zr | 91.224 | ±0.002 | 
| 41 | Nb | 92.90638 | ±0.00002 | 
| 42 | Mo | 95.96 | ±0.02 | 
| 43 | Tc | 98 | |
| 44 | Ru | 101.07 | ±0.02 | 
| 45 | Rh | 102.90550 | ±0.00002 | 
| 46 | Pd | 106.42 | ±0.01 | 
| 47 | Ag | 107.8682 | ±0.0002 | 
| 48 | Cd | 112.411 | ±0.008 | 
| 49 | In | 114.818 | ±0.003 | 
| 50 | Sn | 118.710 | ±0.007 | 
| 51 | Sb | 121.760 | ±0.001 | 
| 52 | Te | 127.60 | ±0.03 | 
| 53 | I | 126.90447 | ±0.00003 | 
| 54 | Xe | 131.293 | ±0.006 | 
| 55 | Cs | 132.9054519 | ±0.0000002 | 
| 56 | Ba | 137.327 | ±0.007 | 
| 57 | La | 138.90547 | ±0.00007 | 
| 58 | Ce | 140.116 | ±0.001 | 
| 59 | Pr | 140.90765 | ±0.00002 | 
| 60 | Nd | 144.242 | ±0.003 | 
| 61 | Pm | 145 | |
| 62 | Sm | 150.36 | ±0.02 | 
| 63 | Eu | 151.964 | ±0.001 | 
| 64 | Gd | 157.25 | ±0.03 | 
| 65 | Tb | 158.92535 | ±0.00002 | 
| 66 | Dy | 162.500 | ±0.001 | 
| 67 | Ho | 164.93032 | ±0.00002 | 
| 68 | Er | 167.259 | ±0.003 | 
| 69 | Tm | 168.93421 | ±0.00002 | 
| 70 | Yb | 173.054 | ±0.005 | 
| 71 | Lu | 174.9668 | ±0.0001 | 
| 72 | Hf | 178.49 | ±0.02 | 
| 73 | Ta | 180.94788 | ±0.00002 | 
| 74 | W | 183.84 | ±0.01 | 
| 75 | Re | 186.207 | ±0.001 | 
| 76 | Os | 190.23 | ±0.03 | 
| 77 | Ir | 192.217 | ±0.003 | 
| 78 | Pt | 195.084 | ±0.009 | 
| 79 | Au | 196.966569 | ±0.000004 | 
| 80 | Hg | 200.59 | ±0.02 | 
| 81 | Tl | 204.3833 | ±0.0002 | 
| 82 | Pb | 207.2 | ±0.1 | 
| 83 | Bi | 208.98040 | ±0.00001 | 
| 84 | Po | 209 | |
| 85 | At | 210 | |
| 86 | Rn | 222 | |
| 87 | Fr | 223 | |
| 88 | Ra | 226 | |
| 89 | Ac | 227 | |
| 90 | Th | 232.03806 | ±0.00002 | 
| 91 | Pa | 231.03588 | ±0.00002 | 
| 92 | U | 238.02891 | ±0.00003 | 
| 93 | Np | 237 | |
| 94 | Pu | 244 | |
| 95 | Am | 243 | |
| 96 | Cm | 247 | |
| 97 | Bk | 247 | |
| 98 | Cf | 251 | |
| 99 | Es | 252 | |
| 100 | Fm | 257 | |
| 101 | Md | 258 | |
| 102 | No | 259 | |
| 103 | Lr | 262 | |
| 104 | Rf | 265 | |
| 105 | Db | 268 | |
| 106 | Sg | 271 | |
| 107 | Bh | 272 | |
| 108 | Hs | 270 | |
| 109 | Mt | 276 | |
| 110 | Ds | 281 | |
| 111 | Rg | 280 | |
| 112 | Cn | 285 | |
| 113 | Uut | 284 | |
| 114 | Uuq | 289 | |
| 115 | Uup | 288 | |
| 116 | Uuh | 293 | |
| 117 | Uus | 292 | |
| 118 | Uuo | 294 | 
Add more output formats: