@@ -137,7 +137,15 @@ Supported table formats are:
137
137
- "simple"
138
138
- "github"
139
139
- "grid"
140
+ - "simple\_ grid"
141
+ - "rounded\_ grid"
142
+ - "double\_ grid"
140
143
- "fancy\_ grid"
144
+ - "outline"
145
+ - "simple\_ outline"
146
+ - "rounded\_ outline"
147
+ - "double\_ outline"
148
+ - "fancy\_ outline"
141
149
- "pipe"
142
150
- "orgtbl"
143
151
- "jira"
@@ -203,7 +211,47 @@ corresponds to the `pipe` format without alignment colons:
203
211
| bacon | 0 |
204
212
+--------+-------+
205
213
206
- ` fancy_grid ` draws a grid using box-drawing characters:
214
+ ` simple_grid ` draws a grid using single-line box-drawing characters:
215
+
216
+ >>> print(tabulate(table, headers, tablefmt="simple_grid"))
217
+ ┌────────┬───────┐
218
+ │ item │ qty │
219
+ ├────────┼───────┤
220
+ │ spam │ 42 │
221
+ ├────────┼───────┤
222
+ │ eggs │ 451 │
223
+ ├────────┼───────┤
224
+ │ bacon │ 0 │
225
+ └────────┴───────┘
226
+
227
+ ` rounded_grid ` draws a grid using single-line box-drawing characters with rounded corners:
228
+
229
+ >>> print(tabulate(table, headers, tablefmt="rounded_grid"))
230
+ ╭────────┬───────╮
231
+ │ item │ qty │
232
+ ├────────┼───────┤
233
+ │ spam │ 42 │
234
+ ├────────┼───────┤
235
+ │ eggs │ 451 │
236
+ ├────────┼───────┤
237
+ │ bacon │ 0 │
238
+ ╰────────┴───────╯
239
+
240
+ ` double_grid ` draws a grid using double-line box-drawing characters:
241
+
242
+ >>> print(tabulate(table, headers, tablefmt="double_grid"))
243
+ ╔════════╦═══════╗
244
+ ║ item ║ qty ║
245
+ ╠════════╬═══════╣
246
+ ║ spam ║ 42 ║
247
+ ╠════════╬═══════╣
248
+ ║ eggs ║ 451 ║
249
+ ╠════════╬═══════╣
250
+ ║ bacon ║ 0 ║
251
+ ╚════════╩═══════╝
252
+
253
+ ` fancy_grid ` draws a grid using a mix of single and
254
+ double-line box-drawing characters:
207
255
208
256
>>> print(tabulate(table, headers, tablefmt="fancy_grid"))
209
257
╒════════╤═══════╕
@@ -216,6 +264,61 @@ corresponds to the `pipe` format without alignment colons:
216
264
│ bacon │ 0 │
217
265
╘════════╧═══════╛
218
266
267
+ ` outline ` is the same as the ` grid ` format but doesn't draw lines between rows:
268
+
269
+ >>> print(tabulate(table, headers, tablefmt="outline"))
270
+ +--------+-------+
271
+ | item | qty |
272
+ +========+=======+
273
+ | spam | 42 |
274
+ | eggs | 451 |
275
+ | bacon | 0 |
276
+ +--------+-------+
277
+
278
+ ` simple_outline ` is the same as the ` simple_grid ` format but doesn't draw lines between rows:
279
+
280
+ >>> print(tabulate(table, headers, tablefmt="simple_outline"))
281
+ ┌────────┬───────┐
282
+ │ item │ qty │
283
+ ├────────┼───────┤
284
+ │ spam │ 42 │
285
+ │ eggs │ 451 │
286
+ │ bacon │ 0 │
287
+ └────────┴───────┘
288
+
289
+ ` rounded_outline ` is the same as the ` rounded_grid ` format but doesn't draw lines between rows:
290
+
291
+ >>> print(tabulate(table, headers, tablefmt="rounded_outline"))
292
+ ╭────────┬───────╮
293
+ │ item │ qty │
294
+ ├────────┼───────┤
295
+ │ spam │ 42 │
296
+ │ eggs │ 451 │
297
+ │ bacon │ 0 │
298
+ ╰────────┴───────╯
299
+
300
+ ` double_outline ` is the same as the ` double_grid ` format but doesn't draw lines between rows:
301
+
302
+ >>> print(tabulate(table, headers, tablefmt="double_outline"))
303
+ ╔════════╦═══════╗
304
+ ║ item ║ qty ║
305
+ ╠════════╬═══════╣
306
+ ║ spam ║ 42 ║
307
+ ║ eggs ║ 451 ║
308
+ ║ bacon ║ 0 ║
309
+ ╚════════╩═══════╝
310
+
311
+ ` fancy_outline ` is the same as the ` fancy_grid ` format but doesn't draw lines between rows:
312
+
313
+ >>> print(tabulate(table, headers, tablefmt="fancy_outline"))
314
+ ╒════════╤═══════╕
315
+ │ item │ qty │
316
+ ╞════════╪═══════╡
317
+ │ spam │ 42 │
318
+ │ eggs │ 451 │
319
+ │ bacon │ 0 │
320
+ ╘════════╧═══════╛
321
+
219
322
` presto ` is like tables formatted by Presto cli:
220
323
221
324
>>> print(tabulate(table, headers, tablefmt="presto"))
@@ -646,6 +749,33 @@ a multiline cell, and headers with a multiline cell:
646
749
647
750
Multiline cells are not well supported for the other table formats.
648
751
752
+ ### Automating Multilines
753
+ While tabulate supports data passed in with multiines entries explicitly provided,
754
+ it also provides some support to help manage this work internally.
755
+
756
+ The ` maxcolwidths ` argument is a list where each entry specifies the max width for
757
+ it's respective column. Any cell that will exceed this will automatically wrap the content.
758
+ To assign the same max width for all columns, a singular int scaler can be used.
759
+
760
+ Use ` None ` for any columns where an explicit maximum does not need to be provided,
761
+ and thus no automate multiline wrapping will take place.
762
+
763
+ The wrapping uses the python standard [ textwrap.wrap] ( https://docs.python.org/3/library/textwrap.html#textwrap.wrap )
764
+ function with default parameters - aside from width.
765
+
766
+ This example demonstrates usage of automatic multiline wrapping, though typically
767
+ the lines being wrapped would probably be significantly longer than this.
768
+
769
+ >>> print(tabulate([["John Smith", "Middle Manager"]], headers=["Name", "Title"], tablefmt="grid", maxcolwidths=[None, 8]))
770
+ +------------+---------+
771
+ | Name | Title |
772
+ +============+=========+
773
+ | John Smith | Middle |
774
+ | | Manager |
775
+ +------------+---------+
776
+
777
+
778
+
649
779
Usage of the command line utility
650
780
---------------------------------
651
781
@@ -688,19 +818,19 @@ At the same time, `tabulate` is comparable to other table
688
818
pretty-printers. Given a 10x10 table (a list of lists) of mixed text and
689
819
numeric data, ` tabulate ` appears to be slower than ` asciitable ` , and
690
820
faster than ` PrettyTable ` and ` texttable ` The following mini-benchmark
691
- was run in Python 3.8.3 in Windows 10 x64 :
821
+ was run in Python 3.8.2 in Ubuntu 20.04 :
692
822
693
- ================================= ========== ===========
694
- Table formatter time, μs rel. time
695
- ================================= ========== ===========
696
- csv to StringIO 12.5 1.0
697
- join with tabs and newlines 15.6 1.3
698
- asciitable (0.8.0) 191.4 15 .4
699
- tabulate (0.8.9 ) 472.8 38.0
700
- tabulate (0.8.9 , WIDE_CHARS_MODE) 789.6 63.4
701
- PrettyTable (0.7.2 ) 879.1 70.6
702
- texttable (1.6.2 ) 1352.2 108.6
703
- ================================= ========== ===========
823
+ ================================== ========== ===========
824
+ Table formatter time, μs rel. time
825
+ ================================== ========== ===========
826
+ csv to StringIO 9.0 1.0
827
+ join with tabs and newlines 10.7 1.2
828
+ asciitable (0.8.0) 174.6 19 .4
829
+ tabulate (0.8.10 ) 385.0 42.8
830
+ tabulate (0.8.10 , WIDE_CHARS_MODE) 509.1 56.5
831
+ PrettyTable (3.3.0 ) 827.7 91.9
832
+ texttable (1.6.4 ) 952.1 105.7
833
+ ================================== ========== ===========
704
834
705
835
706
836
Version history
@@ -767,4 +897,5 @@ Wes Turner, Andrew Tija, Marco Gorelli, Sean McGinnis, danja100,
767
897
endolith, Dominic Davis-Foster, pavlocat, Daniel Aslau, paulc,
768
898
Felix Yan, Shane Loretz, Frank Busse, Harsh Singh, Derek Weitzel,
769
899
Vladimir Vrzić, 서승우 (chrd5273), Georgy Frolov, Christian Cwienk,
770
- Bart Broere, Vilhelm Prytz.
900
+ Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,
901
+ jamescooke, Matt Warner.
0 commit comments