| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 | Metadata-Version: 2.1Name: tabulateVersion: 0.9.0Summary: Pretty-print tabular dataAuthor-email: Sergey Astanin <s.astanin@gmail.com>License: MITProject-URL: Homepage, https://github.com/astanin/python-tabulateClassifier: Development Status :: 4 - BetaClassifier: License :: OSI Approved :: MIT LicenseClassifier: Operating System :: OS IndependentClassifier: Programming Language :: Python :: 3Classifier: Programming Language :: Python :: 3.7Classifier: Programming Language :: Python :: 3.8Classifier: Programming Language :: Python :: 3.9Classifier: Programming Language :: Python :: 3.10Classifier: Topic :: Software Development :: LibrariesRequires-Python: >=3.7Description-Content-Type: text/markdownLicense-File: LICENSEProvides-Extra: widecharsRequires-Dist: wcwidth ; extra == 'widechars'python-tabulate===============Pretty-print tabular data in Python, a library and a command-lineutility.The main use cases of the library are:-   printing small tables without hassle: just one function call,    formatting is guided by the data itself-   authoring tabular data for lightweight plain-text markup: multiple    output formats suitable for further editing or transformation-   readable presentation of mixed textual and numeric data: smart    column alignment, configurable number formatting, alignment by a    decimal pointInstallation------------To install the Python library and the command line utility, run:```shellpip install tabulate```The command line utility will be installed as `tabulate` to `bin` onLinux (e.g. `/usr/bin`); or as `tabulate.exe` to `Scripts` in yourPython installation on Windows (e.g. `C:\Python39\Scripts\tabulate.exe`).You may consider installing the library only for the current user:```shellpip install tabulate --user```In this case the command line utility will be installed to`~/.local/bin/tabulate` on Linux and to`%APPDATA%\Python\Scripts\tabulate.exe` on Windows.To install just the library on Unix-like operating systems:```shellTABULATE_INSTALL=lib-only pip install tabulate```On Windows:```shellset TABULATE_INSTALL=lib-onlypip install tabulate```Build status------------[](https://circleci.com/gh/astanin/python-tabulate/tree/master) [](https://ci.appveyor.com/project/astanin/python-tabulate/branch/master)Library usage-------------The module provides just one function, `tabulate`, which takes a list oflists or another tabular data type as the first argument, and outputs anicely formatted plain-text table:```pycon>>> from tabulate import tabulate>>> table = [["Sun",696000,1989100000],["Earth",6371,5973.6],...          ["Moon",1737,73.5],["Mars",3390,641.85]]>>> print(tabulate(table))-----  ------  -------------Sun    696000     1.9891e+09Earth    6371  5973.6Moon     1737    73.5Mars     3390   641.85-----  ------  -------------```The following tabular data types are supported:-   list of lists or another iterable of iterables-   list or another iterable of dicts (keys as columns)-   dict of iterables (keys as columns)-   list of dataclasses (Python 3.7+ only, field names as columns)-   two-dimensional NumPy array-   NumPy record arrays (names as columns)-   pandas.DataFrameTabulate is a Python3 library.### HeadersThe second optional argument named `headers` defines a list of columnheaders to be used:```pycon>>> print(tabulate(table, headers=["Planet","R (km)", "mass (x 10^29 kg)"]))Planet      R (km)    mass (x 10^29 kg)--------  --------  -------------------Sun         696000           1.9891e+09Earth         6371        5973.6Moon          1737          73.5Mars          3390         641.85```If `headers="firstrow"`, then the first row of data is used:```pycon>>> print(tabulate([["Name","Age"],["Alice",24],["Bob",19]],...                headers="firstrow"))Name      Age------  -----Alice      24Bob        19```If `headers="keys"`, then the keys of a dictionary/dataframe, or columnindices are used. It also works for NumPy record arrays and lists ofdictionaries or named tuples:```pycon>>> print(tabulate({"Name": ["Alice", "Bob"],...                 "Age": [24, 19]}, headers="keys"))  Age  Name-----  ------   24  Alice   19  Bob```### Row IndicesBy default, only pandas.DataFrame tables have an additional columncalled row index. To add a similar column to any other type of table,pass `showindex="always"` or `showindex=True` argument to `tabulate()`.To suppress row indices for all types of data, pass `showindex="never"`or `showindex=False`. To add a custom row index column, pass`showindex=rowIDs`, where `rowIDs` is some iterable:```pycon>>> print(tabulate([["F",24],["M",19]], showindex="always"))-  -  --0  F  241  M  19-  -  --```### Table formatThere is more than one way to format a table in plain text. The thirdoptional argument named `tablefmt` defines how the table is formatted.Supported table formats are:-   "plain"-   "simple"-   "github"-   "grid"-   "simple\_grid"-   "rounded\_grid"-   "heavy\_grid"-   "mixed\_grid"-   "double\_grid"-   "fancy\_grid"-   "outline"-   "simple\_outline"-   "rounded\_outline"-   "heavy\_outline"-   "mixed\_outline"-   "double\_outline"-   "fancy\_outline"-   "pipe"-   "orgtbl"-   "asciidoc"-   "jira"-   "presto"-   "pretty"-   "psql"-   "rst"-   "mediawiki"-   "moinmoin"-   "youtrack"-   "html"-   "unsafehtml"-   "latex"-   "latex\_raw"-   "latex\_booktabs"-   "latex\_longtable"-   "textile"-   "tsv"`plain` tables do not use any pseudo-graphics to draw lines:```pycon>>> table = [["spam",42],["eggs",451],["bacon",0]]>>> headers = ["item", "qty"]>>> print(tabulate(table, headers, tablefmt="plain"))item      qtyspam       42eggs      451bacon       0````simple` is the default format (the default may change in futureversions). It corresponds to `simple_tables` in [Pandoc Markdownextensions](http://johnmacfarlane.net/pandoc/README.html#tables):```pycon>>> print(tabulate(table, headers, tablefmt="simple"))item      qty------  -----spam       42eggs      451bacon       0````github` follows the conventions of GitHub flavored Markdown. Itcorresponds to the `pipe` format without alignment colons:```pycon>>> print(tabulate(table, headers, tablefmt="github"))| item   | qty   ||--------|-------|| spam   | 42    || eggs   | 451   || bacon  | 0     |````grid` is like tables formatted by Emacs'[table.el](http://table.sourceforge.net/) package. It corresponds to`grid_tables` in Pandoc Markdown extensions:```pycon>>> print(tabulate(table, headers, tablefmt="grid"))+--------+-------+| item   |   qty |+========+=======+| spam   |    42 |+--------+-------+| eggs   |   451 |+--------+-------+| bacon  |     0 |+--------+-------+````simple_grid` draws a grid using single-line box-drawing characters:    >>> print(tabulate(table, headers, tablefmt="simple_grid"))    ┌────────┬───────┐    │ item   │   qty │    ├────────┼───────┤    │ spam   │    42 │    ├────────┼───────┤    │ eggs   │   451 │    ├────────┼───────┤    │ bacon  │     0 │    └────────┴───────┘`rounded_grid` draws a grid using single-line box-drawing characters with rounded corners:    >>> print(tabulate(table, headers, tablefmt="rounded_grid"))    ╭────────┬───────╮    │ item   │   qty │    ├────────┼───────┤    │ spam   │    42 │    ├────────┼───────┤    │ eggs   │   451 │    ├────────┼───────┤    │ bacon  │     0 │    ╰────────┴───────╯`heavy_grid` draws a grid using bold (thick) single-line box-drawing characters:    >>> print(tabulate(table, headers, tablefmt="heavy_grid"))    ┏━━━━━━━━┳━━━━━━━┓    ┃ item   ┃   qty ┃    ┣━━━━━━━━╋━━━━━━━┫    ┃ spam   ┃    42 ┃    ┣━━━━━━━━╋━━━━━━━┫    ┃ eggs   ┃   451 ┃    ┣━━━━━━━━╋━━━━━━━┫    ┃ bacon  ┃     0 ┃    ┗━━━━━━━━┻━━━━━━━┛`mixed_grid` draws a grid using a mix of light (thin) and heavy (thick) lines box-drawing characters:    >>> print(tabulate(table, headers, tablefmt="mixed_grid"))    ┍━━━━━━━━┯━━━━━━━┑    │ item   │   qty │    ┝━━━━━━━━┿━━━━━━━┥    │ spam   │    42 │    ├────────┼───────┤    │ eggs   │   451 │    ├────────┼───────┤    │ bacon  │     0 │    ┕━━━━━━━━┷━━━━━━━┙`double_grid` draws a grid using double-line box-drawing characters:    >>> print(tabulate(table, headers, tablefmt="double_grid"))    ╔════════╦═══════╗    ║ item   ║   qty ║    ╠════════╬═══════╣    ║ spam   ║    42 ║    ╠════════╬═══════╣    ║ eggs   ║   451 ║    ╠════════╬═══════╣    ║ bacon  ║     0 ║    ╚════════╩═══════╝`fancy_grid` draws a grid using a mix of single and    double-line box-drawing characters:```pycon>>> print(tabulate(table, headers, tablefmt="fancy_grid"))╒════════╤═══════╕│ item   │   qty │╞════════╪═══════╡│ spam   │    42 │├────────┼───────┤│ eggs   │   451 │├────────┼───────┤│ bacon  │     0 │╘════════╧═══════╛````outline` is the same as the `grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="outline"))    +--------+-------+    | item   |   qty |    +========+=======+    | spam   |    42 |    | eggs   |   451 |    | bacon  |     0 |    +--------+-------+`simple_outline` is the same as the `simple_grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="simple_outline"))    ┌────────┬───────┐    │ item   │   qty │    ├────────┼───────┤    │ spam   │    42 │    │ eggs   │   451 │    │ bacon  │     0 │    └────────┴───────┘`rounded_outline` is the same as the `rounded_grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="rounded_outline"))    ╭────────┬───────╮    │ item   │   qty │    ├────────┼───────┤    │ spam   │    42 │    │ eggs   │   451 │    │ bacon  │     0 │    ╰────────┴───────╯`heavy_outline` is the same as the `heavy_grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="heavy_outline"))    ┏━━━━━━━━┳━━━━━━━┓    ┃ item   ┃   qty ┃    ┣━━━━━━━━╋━━━━━━━┫    ┃ spam   ┃    42 ┃    ┃ eggs   ┃   451 ┃    ┃ bacon  ┃     0 ┃    ┗━━━━━━━━┻━━━━━━━┛`mixed_outline` is the same as the `mixed_grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="mixed_outline"))    ┍━━━━━━━━┯━━━━━━━┑    │ item   │   qty │    ┝━━━━━━━━┿━━━━━━━┥    │ spam   │    42 │    │ eggs   │   451 │    │ bacon  │     0 │    ┕━━━━━━━━┷━━━━━━━┙`double_outline` is the same as the `double_grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="double_outline"))    ╔════════╦═══════╗    ║ item   ║   qty ║    ╠════════╬═══════╣    ║ spam   ║    42 ║    ║ eggs   ║   451 ║    ║ bacon  ║     0 ║    ╚════════╩═══════╝`fancy_outline` is the same as the `fancy_grid` format but doesn't draw lines between rows:    >>> print(tabulate(table, headers, tablefmt="fancy_outline"))    ╒════════╤═══════╕    │ item   │   qty │    ╞════════╪═══════╡    │ spam   │    42 │    │ eggs   │   451 │    │ bacon  │     0 │    ╘════════╧═══════╛`presto` is like tables formatted by Presto cli:```pycon>>> print(tabulate(table, headers, tablefmt="presto")) item   |   qty--------+------- spam   |    42 eggs   |   451 bacon  |     0````pretty` attempts to be close to the format emitted by the PrettyTableslibrary:```pycon>>> print(tabulate(table, headers, tablefmt="pretty"))+-------+-----+| item  | qty |+-------+-----+| spam  | 42  || eggs  | 451 || bacon |  0  |+-------+-----+````psql` is like tables formatted by Postgres' psql cli:```pycon>>> print(tabulate(table, headers, tablefmt="psql"))+--------+-------+| item   |   qty ||--------+-------|| spam   |    42 || eggs   |   451 || bacon  |     0 |+--------+-------+````pipe` follows the conventions of [PHP MarkdownExtra](http://michelf.ca/projects/php-markdown/extra/#table) extension.It corresponds to `pipe_tables` in Pandoc. This format uses colons toindicate column alignment:```pycon>>> print(tabulate(table, headers, tablefmt="pipe"))| item   |   qty ||:-------|------:|| spam   |    42 || eggs   |   451 || bacon  |     0 |````asciidoc` formats data like a simple table of the[AsciiDoctor](https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/#tables)format:```pycon>>> print(tabulate(table, headers, tablefmt="asciidoc"))[cols="8<,7>",options="header"]|====| item   |   qty| spam   |    42| eggs   |   451| bacon  |     0|====````orgtbl` follows the conventions of Emacs[org-mode](http://orgmode.org/manual/Tables.html), and is editable alsoin the minor orgtbl-mode. Hence its name:```pycon>>> print(tabulate(table, headers, tablefmt="orgtbl"))| item   |   qty ||--------+-------|| spam   |    42 || eggs   |   451 || bacon  |     0 |````jira` follows the conventions of Atlassian Jira markup language:```pycon>>> print(tabulate(table, headers, tablefmt="jira"))|| item   ||   qty ||| spam   |    42 || eggs   |   451 || bacon  |     0 |````rst` formats data like a simple table of the[reStructuredText](http://docutils.sourceforge.net/docs/user/rst/quickref.html#tables)format:```pycon>>> print(tabulate(table, headers, tablefmt="rst"))======  =====item      qty======  =====spam       42eggs      451bacon       0======  =====````mediawiki` format produces a table markup used in[Wikipedia](http://www.mediawiki.org/wiki/Help:Tables) and on otherMediaWiki-based sites: ```pycon>>> print(tabulate(table, headers, tablefmt="mediawiki")){| class="wikitable" style="text-align: left;"|+ <!-- caption -->|-! item   !! align="right"|   qty|-| spam   || align="right"|    42|-| eggs   || align="right"|   451|-| bacon  || align="right"|     0|}````moinmoin` format produces a table markup used in[MoinMoin](https://moinmo.in/) wikis:```pycon>>> print(tabulate(table, headers, tablefmt="moinmoin"))|| ''' item   ''' || ''' quantity   ''' ||||  spam    ||  41.999      ||||  eggs    ||  451         ||||  bacon   ||              ||````youtrack` format produces a table markup used in Youtrack tickets:```pycon>>> print(tabulate(table, headers, tablefmt="youtrack"))||  item    ||  quantity   |||   spam    |  41.999      ||   eggs    |  451         ||   bacon   |              |````textile` format produces a table markup used in[Textile](http://redcloth.org/hobix.com/textile/) format:```pycon>>> print(tabulate(table, headers, tablefmt="textile"))|_.  item   |_.   qty ||<. spam    |>.    42 ||<. eggs    |>.   451 ||<. bacon   |>.     0 |````html` produces standard HTML markup as an html.escape'd strwith a ._repr_html_ method so that Jupyter Lab and Notebook display the HTMLand a .str property so that the raw HTML remains accessible.`unsafehtml` table format can be used if an unescaped HTML is required:```pycon>>> print(tabulate(table, headers, tablefmt="html"))<table><tbody><tr><th>item  </th><th style="text-align: right;">  qty</th></tr><tr><td>spam  </td><td style="text-align: right;">   42</td></tr><tr><td>eggs  </td><td style="text-align: right;">  451</td></tr><tr><td>bacon </td><td style="text-align: right;">    0</td></tr></tbody></table>````latex` format creates a `tabular` environment for LaTeX markup,replacing special characters like `_` or `\` to their LaTeXcorrespondents:```pycon>>> print(tabulate(table, headers, tablefmt="latex"))\begin{tabular}{lr}\hline item   &   qty \\\hline spam   &    42 \\ eggs   &   451 \\ bacon  &     0 \\\hline\end{tabular}````latex_raw` behaves like `latex` but does not escape LaTeX commands andspecial characters.`latex_booktabs` creates a `tabular` environment for LaTeX markup usingspacing and style from the `booktabs` package.`latex_longtable` creates a table that can stretch along multiple pages,using the `longtable` package.### Column alignment`tabulate` is smart about column alignment. It detects columns whichcontain only numbers, and aligns them by a decimal point (or flushesthem to the right if they appear to be integers). Text columns areflushed to the left.You can override the default alignment with `numalign` and `stralign`named arguments. Possible column alignments are: `right`, `center`,`left`, `decimal` (only for numbers), and `None` (to disable alignment).Aligning by a decimal point works best when you need to compare numbersat a glance:```pycon>>> print(tabulate([[1.2345],[123.45],[12.345],[12345],[1234.5]]))----------    1.2345  123.45   12.34512345 1234.5----------```Compare this with a more common right alignment:```pycon>>> print(tabulate([[1.2345],[123.45],[12.345],[12345],[1234.5]], numalign="right"))------1.2345123.4512.345 123451234.5------```For `tabulate`, anything which can be parsed as a number is a number.Even numbers represented as strings are aligned properly. This featurecomes in handy when reading a mixed table of text and numbers from afile:```pycon>>> import csv ; from StringIO import StringIO>>> table = list(csv.reader(StringIO("spam, 42\neggs, 451\n")))>>> table[['spam', ' 42'], ['eggs', ' 451']]>>> print(tabulate(table))----  ----spam    42eggs   451----  ----```To disable this feature use `disable_numparse=True`.```pycon>>> print(tabulate.tabulate([["Ver1", "18.0"], ["Ver2","19.2"]], tablefmt="simple", disable_numparse=True))----  ----Ver1  18.0Ver2  19.2----  ----```### Custom column alignment`tabulate` allows a custom column alignment to override the above. The`colalign` argument can be a list or a tuple of `stralign` namedarguments. Possible column alignments are: `right`, `center`, `left`,`decimal` (only for numbers), and `None` (to disable alignment).Omitting an alignment uses the default. For example:```pycon>>> print(tabulate([["one", "two"], ["three", "four"]], colalign=("right",))-----  ----  one  twothree  four-----  ----```### Number formatting`tabulate` allows to define custom number formatting applied to allcolumns of decimal numbers. Use `floatfmt` named argument:```pycon>>> print(tabulate([["pi",3.141593],["e",2.718282]], floatfmt=".4f"))--  ------pi  3.1416e   2.7183--  ------````floatfmt` argument can be a list or a tuple of format strings, one percolumn, in which case every column may have different number formatting:```pycon>>> print(tabulate([[0.12345, 0.12345, 0.12345]], floatfmt=(".1f", ".3f")))---  -----  -------0.1  0.123  0.12345---  -----  -------````intfmt` works similarly for integers    >>> print(tabulate([["a",1000],["b",90000]], intfmt=","))    -  ------    a   1,000    b  90,000    -  ------### Text formattingBy default, `tabulate` removes leading and trailing whitespace from textcolumns. To disable whitespace removal, set the global module-level flag`PRESERVE_WHITESPACE`:```pythonimport tabulatetabulate.PRESERVE_WHITESPACE = True```### Wide (fullwidth CJK) symbolsTo properly align tables which contain wide characters (typicallyfullwidth glyphs from Chinese, Japanese or Korean languages), the usershould install `wcwidth` library. To install it together with`tabulate`:```shellpip install tabulate[widechars]```Wide character support is enabled automatically if `wcwidth` library isalready installed. To disable wide characters support withoutuninstalling `wcwidth`, set the global module-level flag`WIDE_CHARS_MODE`:```pythonimport tabulatetabulate.WIDE_CHARS_MODE = False```### Multiline cellsMost table formats support multiline cell text (text containing newlinecharacters). The newline characters are honored as line breakcharacters.Multiline cells are supported for data rows and for header rows.Further automatic line breaks are not inserted. Of course, some outputformats such as latex or html handle automatic formatting of the cellcontent on their own, but for those that don't, the newline charactersin the input cell text are the only means to break a line in cell text.Note that some output formats (e.g. simple, or plain) do not representrow delimiters, so that the representation of multiline cells in suchformats may be ambiguous to the reader.The following examples of formatted output use the following table witha multiline cell, and headers with a multiline cell:```pycon>>> table = [["eggs",451],["more\nspam",42]]>>> headers = ["item\nname", "qty"]````plain` tables:```pycon>>> print(tabulate(table, headers, tablefmt="plain"))item      qtynameeggs      451more       42spam````simple` tables:```pycon>>> print(tabulate(table, headers, tablefmt="simple"))item      qtyname------  -----eggs      451more       42spam````grid` tables:```pycon>>> print(tabulate(table, headers, tablefmt="grid"))+--------+-------+| item   |   qty || name   |       |+========+=======+| eggs   |   451 |+--------+-------+| more   |    42 || spam   |       |+--------+-------+````fancy_grid` tables:```pycon>>> print(tabulate(table, headers, tablefmt="fancy_grid"))╒════════╤═══════╕│ item   │   qty ││ name   │       │╞════════╪═══════╡│ eggs   │   451 │├────────┼───────┤│ more   │    42 ││ spam   │       │╘════════╧═══════╛````pipe` tables:```pycon>>> print(tabulate(table, headers, tablefmt="pipe"))| item   |   qty || name   |       ||:-------|------:|| eggs   |   451 || more   |    42 || spam   |       |````orgtbl` tables:```pycon>>> print(tabulate(table, headers, tablefmt="orgtbl"))| item   |   qty || name   |       ||--------+-------|| eggs   |   451 || more   |    42 || spam   |       |````jira` tables:```pycon>>> print(tabulate(table, headers, tablefmt="jira"))| item   |   qty || name   |       ||:-------|------:|| eggs   |   451 || more   |    42 || spam   |       |````presto` tables:```pycon>>> print(tabulate(table, headers, tablefmt="presto")) item   |   qty name   |--------+------- eggs   |   451 more   |    42 spam   |````pretty` tables:```pycon>>> print(tabulate(table, headers, tablefmt="pretty"))+------+-----+| item | qty || name |     |+------+-----+| eggs | 451 || more | 42  || spam |     |+------+-----+````psql` tables:```pycon>>> print(tabulate(table, headers, tablefmt="psql"))+--------+-------+| item   |   qty || name   |       ||--------+-------|| eggs   |   451 || more   |    42 || spam   |       |+--------+-------+````rst` tables:```pycon>>> print(tabulate(table, headers, tablefmt="rst"))======  =====item      qtyname======  =====eggs      451more       42spam======  =====```Multiline cells are not well-supported for the other table formats.### Automating MultilinesWhile tabulate supports data passed in with multilines entries explicitly provided,it also provides some support to help manage this work internally.The `maxcolwidths` argument is a list where each entry specifies the max width forit's respective column. Any cell that will exceed this will automatically wrap the content.To assign the same max width for all columns, a singular int scaler can be used.Use `None` for any columns where an explicit maximum does not need to be provided,and thus no automate multiline wrapping will take place.The wrapping uses the python standard [textwrap.wrap](https://docs.python.org/3/library/textwrap.html#textwrap.wrap)function with default parameters - aside from width.This example demonstrates usage of automatic multiline wrapping, though typicallythe lines being wrapped would probably be significantly longer than this.```pycon>>> print(tabulate([["John Smith", "Middle Manager"]], headers=["Name", "Title"], tablefmt="grid", maxcolwidths=[None, 8]))+------------+---------+| Name       | Title   |+============+=========+| John Smith | Middle  ||            | Manager |+------------+---------+```### Adding Separating linesOne might want to add one or more separating lines to highlight different sections in a table.The separating lines will be of the same type as the one defined by the specified formatter as either thelinebetweenrows, linebelowheader, linebelow, lineabove or just a simple empty line when none is defined for the formatter    >>> from tabulate import tabulate, SEPARATING_LINE    table = [["Earth",6371],             ["Mars",3390],             SEPARATING_LINE,             ["Moon",1737]]    print(tabulate(table, tablefmt="simple"))    -----  ----    Earth  6371    Mars   3390    -----  ----    Moon   1737    -----  ----### ANSI supportANSI escape codes are non-printable byte sequences usually used for terminal operations like settingcolor output or modifying cursor positions. Because multi-byte ANSI sequences are inherently non-printable,they can still introduce unwanted extra length to strings. For example:    >>> len('\033[31mthis text is red\033[0m')  # printable length is 16    25To deal with this, string lengths are calculated after first removing all ANSI escape sequences. This ensuresthat the actual printable length is used for column widths, rather than the byte length. In the final, printabletable, however, ANSI escape sequences are not removed so the original styling is preserved.Some terminals support a special grouping of ANSI escape sequences that are intended to display hyperlinksmuch in the same way they are shown in browsers. These are handled just as mentioned before: non-printableANSI escape sequences are removed prior to string length calculation. The only diifference with escapedhyperlinks is that column width will be based on the length of the URL _text_ rather than the URLitself (terminals would show this text). For example:    >>> len('\x1b]8;;https://example.com\x1b\\example\x1b]8;;\x1b\\')  # display length is 7, showing 'example'    45Usage of the command line utility---------------------------------    Usage: tabulate [options] [FILE ...]    FILE                      a filename of the file with tabular data;                              if "-" or missing, read data from stdin.    Options:    -h, --help                show this message    -1, --header              use the first row of data as a table header    -o FILE, --output FILE    print table to FILE (default: stdout)    -s REGEXP, --sep REGEXP   use a custom column separator (default: whitespace)    -F FPFMT, --float FPFMT   floating point number format (default: g)    -I INTFMT, --int INTFMT   integer point number format (default: "")    -f FMT, --format FMT      set output table format; supported formats:                              plain, simple, github, grid, fancy_grid, pipe,                              orgtbl, rst, mediawiki, html, latex, latex_raw,                              latex_booktabs, latex_longtable, tsv                              (default: simple)Performance considerations--------------------------Such features as decimal point alignment and trying to parse everythingas a number imply that `tabulate`:-   has to "guess" how to print a particular tabular data type-   needs to keep the entire table in-memory-   has to "transpose" the table twice-   does much more work than it may appearIt may not be suitable for serializing really big tables (but who'sgoing to do that, anyway?) or printing tables in performance sensitiveapplications. `tabulate` is about two orders of magnitude slower thansimply joining lists of values with a tab, comma, or other separator.At the same time, `tabulate` is comparable to other tablepretty-printers. Given a 10x10 table (a list of lists) of mixed text andnumeric data, `tabulate` appears to be slower than `asciitable`, andfaster than `PrettyTable` and `texttable` The following mini-benchmarkwas run in Python 3.9.13 on Windows 10:    =================================  ==========  ===========    Table formatter                      time, μs    rel. time    =================================  ==========  ===========    csv to StringIO                          12.5          1.0    join with tabs and newlines              14.6          1.2    asciitable (0.8.0)                      192.0         15.4    tabulate (0.9.0)                        483.5         38.7    tabulate (0.9.0, WIDE_CHARS_MODE)       637.6         51.1    PrettyTable (3.4.1)                    1080.6         86.6    texttable (1.6.4)                      1390.3        111.4    =================================  ==========  ===========Version history---------------The full version history can be found at the [changelog](https://github.com/astanin/python-tabulate/blob/master/CHANGELOG).How to contribute-----------------Contributions should include tests and an explanation for the changesthey propose. Documentation (examples, docstrings, README.md) should beupdated accordingly.This project uses [pytest](https://docs.pytest.org/) testingframework and [tox](https://tox.readthedocs.io/) to automate testing indifferent environments. Add tests to one of the files in the `test/`folder.To run tests on all supported Python versions, make sure all Pythoninterpreters, `pytest` and `tox` are installed, then run `tox` in the rootof the project source tree.On Linux `tox` expects to find executables like `python3.7`, `python3.8` etc.On Windows it looks for `C:\Python37\python.exe`, `C:\Python38\python.exe` etc. respectively.One way to install all the required versions of the Python interpreter is to use [pyenv](https://github.com/pyenv/pyenv).All versions can then be easily installed with something like:     pyenv install 3.7.12     pyenv install 3.8.12     ...Don't forget to change your `PATH` so that `tox` knows how to find all the installed versions. Something like     export PATH="${PATH}:${HOME}/.pyenv/shims"To test only some Python environments, use `-e` option. For example, totest only against Python 3.7 and Python 3.10, run:```shelltox -e py37,py310```in the root of the project source tree.To enable NumPy and Pandas tests, run:```shelltox -e py37-extra,py310-extra```(this may take a long time the first time, because NumPy and Pandas willhave to be installed in the new virtual environments)To fix code formatting:```shelltox -e lint```See `tox.ini` file to learn how to use to testindividual Python versions.Contributors------------Sergey Astanin, Pau Tallada Crespí, Erwin Marsi, Mik Kocikowski, BillRyder, Zach Dwiel, Frederik Rietdijk, Philipp Bogensberger, Greg(anonymous), Stefan Tatschner, Emiel van Miltenburg, Brandon Bennett,Amjith Ramanujam, Jan Schulz, Simon Percivall, Javier SantacruzLópez-Cepero, Sam Denton, Alexey Ziyangirov, acaird, Cesar Sanchez,naught101, John Vandenberg, Zack Dever, Christian Clauss, BenjaminMaier, Andy MacKinlay, Thomas Roten, Jue Wang, Joe King, Samuel Phan,Nick Satterly, Daniel Robbins, Dmitry B, Lars Butler, Andreas Maier,Dick Marinus, Sébastien Celles, Yago González, Andrew Gaul, Wim Glenn,Jean Michel Rouly, Tim Gates, John Vandenberg, Sorin Sbarnea,Wes Turner, Andrew Tija, Marco Gorelli, Sean McGinnis, danja100,endolith, Dominic Davis-Foster, pavlocat, Daniel Aslau, paulc,Felix Yan, Shane Loretz, Frank Busse, Harsh Singh, Derek Weitzel,Vladimir Vrzić, 서승우 (chrd5273), Georgy Frolov, Christian Cwienk,Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,jamescooke, Matt Warner, Jérôme Provensal, Kevin Deldycke,Kian-Meng Ang, Kevin Patterson, Shodhan Save, cleoold, KOLANICH,Vijaya Krishna Kasula, Furcy Pin, Christian Fibich, Shaun Duncan,Dimitri Papadopoulos.
 |