@@ -25,8 +25,7 @@ pip install tabulate
25
25
26
26
The command line utility will be installed as ` tabulate ` to ` bin ` on
27
27
Linux (e.g. ` /usr/bin ` ); or as ` tabulate.exe ` to ` Scripts ` in your
28
- Python installation on Windows (e.g.
29
- ` C:\Python39\Scripts\tabulate.exe ` ).
28
+ Python installation on Windows (e.g. ` C:\Python39\Scripts\tabulate.exe ` ).
30
29
31
30
You may consider installing the library only for the current user:
32
31
@@ -82,6 +81,7 @@ The following tabular data types are supported:
82
81
- list of lists or another iterable of iterables
83
82
- list or another iterable of dicts (keys as columns)
84
83
- dict of iterables (keys as columns)
84
+ - list of dataclasses (Python 3.7+ only, field names as columns)
85
85
- two-dimensional NumPy array
86
86
- NumPy record arrays (names as columns)
87
87
- pandas.DataFrame
@@ -155,7 +155,15 @@ Supported table formats are:
155
155
- "simple"
156
156
- "github"
157
157
- "grid"
158
+ - "simple\_ grid"
159
+ - "rounded\_ grid"
160
+ - "double\_ grid"
158
161
- "fancy\_ grid"
162
+ - "outline"
163
+ - "simple\_ outline"
164
+ - "rounded\_ outline"
165
+ - "double\_ outline"
166
+ - "fancy\_ outline"
159
167
- "pipe"
160
168
- "orgtbl"
161
169
- "jira"
@@ -229,7 +237,47 @@ corresponds to the `pipe` format without alignment colons:
229
237
+--------+-------+
230
238
```
231
239
232
- ` fancy_grid ` draws a grid using box-drawing characters:
240
+ ` simple_grid ` draws a grid using single-line box-drawing characters:
241
+
242
+ >>> print(tabulate(table, headers, tablefmt="simple_grid"))
243
+ ┌────────┬───────┐
244
+ │ item │ qty │
245
+ ├────────┼───────┤
246
+ │ spam │ 42 │
247
+ ├────────┼───────┤
248
+ │ eggs │ 451 │
249
+ ├────────┼───────┤
250
+ │ bacon │ 0 │
251
+ └────────┴───────┘
252
+
253
+ ` rounded_grid ` draws a grid using single-line box-drawing characters with rounded corners:
254
+
255
+ >>> print(tabulate(table, headers, tablefmt="rounded_grid"))
256
+ ╭────────┬───────╮
257
+ │ item │ qty │
258
+ ├────────┼───────┤
259
+ │ spam │ 42 │
260
+ ├────────┼───────┤
261
+ │ eggs │ 451 │
262
+ ├────────┼───────┤
263
+ │ bacon │ 0 │
264
+ ╰────────┴───────╯
265
+
266
+ ` double_grid ` draws a grid using double-line box-drawing characters:
267
+
268
+ >>> print(tabulate(table, headers, tablefmt="double_grid"))
269
+ ╔════════╦═══════╗
270
+ ║ item ║ qty ║
271
+ ╠════════╬═══════╣
272
+ ║ spam ║ 42 ║
273
+ ╠════════╬═══════╣
274
+ ║ eggs ║ 451 ║
275
+ ╠════════╬═══════╣
276
+ ║ bacon ║ 0 ║
277
+ ╚════════╩═══════╝
278
+
279
+ ` fancy_grid ` draws a grid using a mix of single and
280
+ double-line box-drawing characters:
233
281
234
282
``` pycon
235
283
>>> print (tabulate(table, headers, tablefmt = " fancy_grid" ))
@@ -244,6 +292,61 @@ corresponds to the `pipe` format without alignment colons:
244
292
╘════════╧═══════╛
245
293
```
246
294
295
+ ` outline ` is the same as the ` grid ` format but doesn't draw lines between rows:
296
+
297
+ >>> print(tabulate(table, headers, tablefmt="outline"))
298
+ +--------+-------+
299
+ | item | qty |
300
+ +========+=======+
301
+ | spam | 42 |
302
+ | eggs | 451 |
303
+ | bacon | 0 |
304
+ +--------+-------+
305
+
306
+ ` simple_outline ` is the same as the ` simple_grid ` format but doesn't draw lines between rows:
307
+
308
+ >>> print(tabulate(table, headers, tablefmt="simple_outline"))
309
+ ┌────────┬───────┐
310
+ │ item │ qty │
311
+ ├────────┼───────┤
312
+ │ spam │ 42 │
313
+ │ eggs │ 451 │
314
+ │ bacon │ 0 │
315
+ └────────┴───────┘
316
+
317
+ ` rounded_outline ` is the same as the ` rounded_grid ` format but doesn't draw lines between rows:
318
+
319
+ >>> print(tabulate(table, headers, tablefmt="rounded_outline"))
320
+ ╭────────┬───────╮
321
+ │ item │ qty │
322
+ ├────────┼───────┤
323
+ │ spam │ 42 │
324
+ │ eggs │ 451 │
325
+ │ bacon │ 0 │
326
+ ╰────────┴───────╯
327
+
328
+ ` double_outline ` is the same as the ` double_grid ` format but doesn't draw lines between rows:
329
+
330
+ >>> print(tabulate(table, headers, tablefmt="double_outline"))
331
+ ╔════════╦═══════╗
332
+ ║ item ║ qty ║
333
+ ╠════════╬═══════╣
334
+ ║ spam ║ 42 ║
335
+ ║ eggs ║ 451 ║
336
+ ║ bacon ║ 0 ║
337
+ ╚════════╩═══════╝
338
+
339
+ ` fancy_outline ` is the same as the ` fancy_grid ` format but doesn't draw lines between rows:
340
+
341
+ >>> print(tabulate(table, headers, tablefmt="fancy_outline"))
342
+ ╒════════╤═══════╕
343
+ │ item │ qty │
344
+ ╞════════╪═══════╡
345
+ │ spam │ 42 │
346
+ │ eggs │ 451 │
347
+ │ bacon │ 0 │
348
+ ╘════════╧═══════╛
349
+
247
350
` presto ` is like tables formatted by Presto cli:
248
351
249
352
``` pycon
@@ -532,6 +635,14 @@ column, in which case every column may have different number formatting:
532
635
--- ----- -------
533
636
```
534
637
638
+ ` intfmt ` works similarly for integers
639
+
640
+ >>> print(tabulate([["a",1000],["b",90000]], intfmt=","))
641
+ - ------
642
+ a 1,000
643
+ b 90,000
644
+ - ------
645
+
535
646
### Text formatting
536
647
537
648
By default, ` tabulate ` removes leading and trailing whitespace from text
@@ -745,7 +856,7 @@ To assign the same max width for all columns, a singular int scaler can be used.
745
856
Use ` None ` for any columns where an explicit maximum does not need to be provided,
746
857
and thus no automate multiline wrapping will take place.
747
858
748
- The wraping uses the python standard [ textwrap.wrap] ( https://docs.python.org/3/library/textwrap.html#textwrap.wrap )
859
+ The wrapping uses the python standard [ textwrap.wrap] ( https://docs.python.org/3/library/textwrap.html#textwrap.wrap )
749
860
function with default parameters - aside from width.
750
861
751
862
This example demonstrates usage of automatic multiline wrapping, though typically
@@ -777,6 +888,7 @@ Usage of the command line utility
777
888
-o FILE, --output FILE print table to FILE (default: stdout)
778
889
-s REGEXP, --sep REGEXP use a custom column separator (default: whitespace)
779
890
-F FPFMT, --float FPFMT floating point number format (default: g)
891
+ -I INTFMT, --int INTFMT integer point number format (default: "")
780
892
-f FMT, --format FMT set output table format; supported formats:
781
893
plain, simple, github, grid, fancy_grid, pipe,
782
894
orgtbl, rst, mediawiki, html, latex, latex_raw,
@@ -803,19 +915,19 @@ At the same time, `tabulate` is comparable to other table
803
915
pretty-printers. Given a 10x10 table (a list of lists) of mixed text and
804
916
numeric data, ` tabulate ` appears to be slower than ` asciitable ` , and
805
917
faster than ` PrettyTable ` and ` texttable ` The following mini-benchmark
806
- was run in Python 3.8.3 in Windows 10 x64 :
918
+ was run in Python 3.8.2 in Ubuntu 20.04 :
807
919
808
- ================================= ========== ===========
809
- Table formatter time, μs rel. time
810
- ================================= ========== ===========
811
- csv to StringIO 12.5 1.0
812
- join with tabs and newlines 15.6 1.3
813
- asciitable (0.8.0) 191.4 15 .4
814
- tabulate (0.8.9 ) 472.8 38.0
815
- tabulate (0.8.9 , WIDE_CHARS_MODE) 789.6 63.4
816
- PrettyTable (0.7.2 ) 879.1 70.6
817
- texttable (1.6.2 ) 1352.2 108.6
818
- ================================= ========== ===========
920
+ ================================== ========== ===========
921
+ Table formatter time, μs rel. time
922
+ ================================== ========== ===========
923
+ csv to StringIO 9.0 1.0
924
+ join with tabs and newlines 10.7 1.2
925
+ asciitable (0.8.0) 174.6 19 .4
926
+ tabulate (0.8.10 ) 385.0 42.8
927
+ tabulate (0.8.10 , WIDE_CHARS_MODE) 509.1 56.5
928
+ PrettyTable (3.3.0 ) 827.7 91.9
929
+ texttable (1.6.4 ) 952.1 105.7
930
+ ================================== ========== ===========
819
931
820
932
821
933
Version history
@@ -839,10 +951,8 @@ To run tests on all supported Python versions, make sure all Python
839
951
interpreters, ` pytest ` and ` tox ` are installed, then run ` tox ` in the root
840
952
of the project source tree.
841
953
842
- On Linux ` tox ` expects to find executables like ` python2.6 ` ,
843
- ` python2.7 ` , ` python3.4 ` etc. On Windows it looks for
844
- ` C:\Python26\python.exe ` , ` C:\Python27\python.exe ` and
845
- ` C:\Python34\python.exe ` respectively.
954
+ On Linux ` tox ` expects to find executables like ` python3.7 ` , ` python3.8 ` etc.
955
+ On Windows it looks for ` C:\Python37\python.exe ` , ` C:\Python38\python.exe ` etc. respectively.
846
956
847
957
To test only some Python environments, use ` -e ` option. For example, to
848
958
test only against Python 3.7 and Python 3.10, run:
@@ -888,4 +998,5 @@ Wes Turner, Andrew Tija, Marco Gorelli, Sean McGinnis, danja100,
888
998
endolith, Dominic Davis-Foster, pavlocat, Daniel Aslau, paulc,
889
999
Felix Yan, Shane Loretz, Frank Busse, Harsh Singh, Derek Weitzel,
890
1000
Vladimir Vrzić, 서승우 (chrd5273), Georgy Frolov, Christian Cwienk,
891
- Bart Broere, Vilhelm Prytz.
1001
+ Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,
1002
+ jamescooke, Matt Warner.
0 commit comments