{ "info": { "author": "Sergey Astanin", "author_email": "s.astanin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries" ], "description": "===============\npython-tabulate\n===============\n\nPretty-print tabular data in Python, a library and a command-line\nutility.\n\nThe main use cases of the library are:\n\n* printing small tables without hassle: just one function call,\n formatting is guided by the data itself\n\n* authoring tabular data for lightweight plain-text markup: multiple\n output formats suitable for further editing or transformation\n\n* readable presentation of mixed textual and numeric data: smart\n column alignment, configurable number formatting, alignment by a\n decimal point\n\n\nInstallation\n------------\n\nTo install the Python library and the command line utility, run::\n\n pip install tabulate\n\nThe command line utility will be installed as ``tabulate`` to ``bin`` on Linux\n(e.g. ``/usr/bin``); or as ``tabulate.exe`` to ``Scripts`` in your Python\ninstallation on Windows (e.g. ``C:\\Python27\\Scripts\\tabulate.exe``).\n\nYou may consider installing the library only for the current user::\n\n pip install tabulate --user\n\nIn this case the command line utility will be installed to ``~/.local/bin/tabulate``\non Linux and to ``%APPDATA%\\Python\\Scripts\\tabulate.exe`` on Windows.\n\nTo install just the library on Unix-like operating systems::\n\n TABULATE_INSTALL=lib-only pip install tabulate\n\nOn Windows::\n\n set TABULATE_INSTALL=lib-only\n pip install tabulate\n\n\nLibrary usage\n-------------\n\nThe module provides just one function, ``tabulate``, which takes a\nlist of lists or another tabular data type as the first argument,\nand outputs a nicely formatted plain-text table::\n\n >>> from tabulate import tabulate\n\n >>> table = [[\"Sun\",696000,1989100000],[\"Earth\",6371,5973.6],\n ... [\"Moon\",1737,73.5],[\"Mars\",3390,641.85]]\n >>> print(tabulate(table))\n ----- ------ -------------\n Sun 696000 1.9891e+09\n Earth 6371 5973.6\n Moon 1737 73.5\n Mars 3390 641.85\n ----- ------ -------------\n\nThe following tabular data types are supported:\n\n* list of lists or another iterable of iterables\n* list or another iterable of dicts (keys as columns)\n* dict of iterables (keys as columns)\n* two-dimensional NumPy array\n* NumPy record arrays (names as columns)\n* pandas.DataFrame\n\nExamples in this file use Python2. Tabulate supports Python3 too.\n\n\nHeaders\n~~~~~~~\n\nThe second optional argument named ``headers`` defines a list of\ncolumn headers to be used::\n\n >>> print(tabulate(table, headers=[\"Planet\",\"R (km)\", \"mass (x 10^29 kg)\"]))\n Planet R (km) mass (x 10^29 kg)\n -------- -------- -------------------\n Sun 696000 1.9891e+09\n Earth 6371 5973.6\n Moon 1737 73.5\n Mars 3390 641.85\n\nIf ``headers=\"firstrow\"``, then the first row of data is used::\n\n >>> print(tabulate([[\"Name\",\"Age\"],[\"Alice\",24],[\"Bob\",19]],\n ... headers=\"firstrow\"))\n Name Age\n ------ -----\n Alice 24\n Bob 19\n\n\nIf ``headers=\"keys\"``, then the keys of a dictionary/dataframe, or\ncolumn indices are used. It also works for NumPy record arrays and\nlists of dictionaries or named tuples::\n\n >>> print(tabulate({\"Name\": [\"Alice\", \"Bob\"],\n ... \"Age\": [24, 19]}, headers=\"keys\"))\n Age Name\n ----- ------\n 24 Alice\n 19 Bob\n\n\nRow Indices\n~~~~~~~~~~~\n\nBy default, only pandas.DataFrame tables have an additional column\ncalled row index. To add a similar column to any other type of table,\npass ``showindex=\"always\"`` or ``showindex=True`` argument to\n``tabulate()``. To suppress row indices for all types of data, pass\n``showindex=\"never\"`` or ``showindex=False``. To add a custom row\nindex column, pass ``showindex=rowIDs``, where ``rowIDs`` is some\niterable::\n\n >>> print(tabulate([[\"F\",24],[\"M\",19]], showindex=\"always\"))\n - - --\n 0 F 24\n 1 M 19\n - - --\n\n\nTable format\n~~~~~~~~~~~~\n\nThere is more than one way to format a table in plain text.\nThe third optional argument named ``tablefmt`` defines\nhow the table is formatted.\n\nSupported table formats are:\n\n- \"plain\"\n- \"simple\"\n- \"github\"\n- \"grid\"\n- \"fancy_grid\"\n- \"pipe\"\n- \"orgtbl\"\n- \"jira\"\n- \"presto\"\n- \"psql\"\n- \"rst\"\n- \"mediawiki\"\n- \"moinmoin\"\n- \"youtrack\"\n- \"html\"\n- \"latex\"\n- \"latex_raw\"\n- \"latex_booktabs\"\n- \"textile\"\n\n``plain`` tables do not use any pseudo-graphics to draw lines::\n\n >>> table = [[\"spam\",42],[\"eggs\",451],[\"bacon\",0]]\n >>> headers = [\"item\", \"qty\"]\n >>> print(tabulate(table, headers, tablefmt=\"plain\"))\n item qty\n spam 42\n eggs 451\n bacon 0\n\n``simple`` is the default format (the default may change in future\nversions). It corresponds to ``simple_tables`` in `Pandoc Markdown\nextensions`::\n\n >>> print(tabulate(table, headers, tablefmt=\"simple\"))\n item qty\n ------ -----\n spam 42\n eggs 451\n bacon 0\n\n``github`` follows the conventions of `Github flavored Markdown`. It\ncorresponds to the ``pipe`` format without alignment colons::\n\n >>> print(tabulate(table, headers, tablefmt=\"github\"))\n | item | qty |\n |--------|-------|\n | spam | 42 |\n | eggs | 451 |\n | bacon | 0 |\n\n\n``grid`` is like tables formatted by Emacs' `table.el`\npackage. It corresponds to ``grid_tables`` in Pandoc Markdown\nextensions::\n\n >>> print(tabulate(table, headers, tablefmt=\"grid\"))\n +--------+-------+\n | item | qty |\n +========+=======+\n | spam | 42 |\n +--------+-------+\n | eggs | 451 |\n +--------+-------+\n | bacon | 0 |\n +--------+-------+\n\n``fancy_grid`` draws a grid using box-drawing characters::\n\n >>> print(tabulate(table, headers, tablefmt=\"fancy_grid\"))\n \u2552\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2555\n \u2502 item \u2502 qty \u2502\n \u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561\n \u2502 spam \u2502 42 \u2502\n \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 eggs \u2502 451 \u2502\n \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n \u2502 bacon \u2502 0 \u2502\n \u2558\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255b\n\n``presto`` is like tables formatted by Presto cli::\n\n >>> print(tabulate(table, headers, tablefmt=\"presto\"))\n item | qty\n --------+-------\n spam | 42\n eggs | 451\n bacon | 0\n\n``psql`` is like tables formatted by Postgres' psql cli::\n\n >>> print(tabulate(table, headers, tablefmt=\"psql\"))\n +--------+-------+\n | item | qty |\n |--------+-------|\n | spam | 42 |\n | eggs | 451 |\n | bacon | 0 |\n +--------+-------+\n\n``pipe`` follows the conventions of `PHP Markdown Extra` extension. It\ncorresponds to ``pipe_tables`` in Pandoc. This format uses colons to\nindicate column alignment::\n\n >>> print(tabulate(table, headers, tablefmt=\"pipe\"))\n | item | qty |\n |:-------|------:|\n | spam | 42 |\n | eggs | 451 |\n | bacon | 0 |\n\n``orgtbl`` follows the conventions of Emacs `org-mode`, and is editable\nalso in the minor `orgtbl-mode`. Hence its name::\n\n >>> print(tabulate(table, headers, tablefmt=\"orgtbl\"))\n | item | qty |\n |--------+-------|\n | spam | 42 |\n | eggs | 451 |\n | bacon | 0 |\n\n``jira`` follows the conventions of Atlassian Jira markup language::\n\n >>> print(tabulate(table, headers, tablefmt=\"jira\"))\n || item || qty ||\n | spam | 42 |\n | eggs | 451 |\n | bacon | 0 |\n\n``rst`` formats data like a simple table of the `reStructuredText` format::\n\n >>> print(tabulate(table, headers, tablefmt=\"rst\"))\n ====== =====\n item qty\n ====== =====\n spam 42\n eggs 451\n bacon 0\n ====== =====\n\n``mediawiki`` format produces a table markup used in `Wikipedia` and on\nother MediaWiki-based sites::\n\n >>> print(tabulate(table, headers, tablefmt=\"mediawiki\"))\n {| class=\"wikitable\" style=\"text-align: left;\"\n |+ \n |-\n ! item !! align=\"right\"| qty\n |-\n | spam || align=\"right\"| 42\n |-\n | eggs || align=\"right\"| 451\n |-\n | bacon || align=\"right\"| 0\n |}\n\n``moinmoin`` format produces a table markup used in `MoinMoin`\nwikis::\n\n >>> print(tabulate(table, headers, tablefmt=\"moinmoin\"))\n || ''' item ''' || ''' quantity ''' ||\n || spam || 41.999 ||\n || eggs || 451 ||\n || bacon || ||\n\n``youtrack`` format produces a table markup used in Youtrack\ntickets::\n\n >>> print(tabulate(table, headers, tablefmt=\"youtrack\"))\n || item || quantity ||\n | spam | 41.999 |\n | eggs | 451 |\n | bacon | |\n\n``textile`` format produces a table markup used in `Textile` format::\n\n >>> print(tabulate(table, headers, tablefmt=\"textile\"))\n |_. item |_. qty |\n |<. spam |>. 42 |\n |<. eggs |>. 451 |\n |<. bacon |>. 0 |\n\n``html`` produces standard HTML markup::\n\n >>> print(tabulate(table, headers, tablefmt=\"html\"))\n
| item | qty |
|---|---|
| spam | 42 |
| eggs | 451 |
| bacon | 0 |