PrettyTable
PrettyTable is a simple Python library designed to make it quick and easy to represent tabular data in visually appealing ASCII tables. It was inspired by the ASCII tables used in the PostgreSQL shell psql. PrettyTable allows for selection of which columns are to be printed, independent alignment of columns (left or right justified or centred) and printing of "sub-tables" by specifying a row range.
PrettyTable has moved!
As of PrettyTable 0.5 (released May 26, 2009), PrettyTable development has moved to a Google code project. All future releases, documentation, etc. will be published at that page and not at this one, so please update your bookmarks! PrettyTable was an unexpected hit and quickly outgrew the sorts of facilities I could easily provide myself. The Google code page features a Wiki for documentation, three "Google groups" (mailing lists, basically) and a web-browsable Subversion repository. Check it out!
Links to old pages associated with PrettyTable 0.1 through 0.4 are maintained below for historical interest.
Old versions / History
PrettyTable 0.4 - May 13, 2009 (Download) (Webpage)
- Added add_column method to enable building tables up column-by-column.
- Added print_HTML and get_HTML_string methods to enable HTML table production.
- Added set_border_chars method to enable control over characters used to draw the table border.
- Added set_left_padding and set_right_padding methods to allow independent padding control for both sides of a column.
- Added sortby option to enable column sorting.
- Added header option to enable switching off field name printing at top of table.
- Modified hrules option to enable greater control over presence of horizontal lines.
- Added border option to enable switching off all line printing.
Thanks to Tim Cera, Chris Clark, Alexander Lamaison for suggesting and helping to test many of the new features in this release.
PrettyTable 0.3 - May 01, 2009 (Download) (Webpage)
- Added padding_width option to control the number of spaces between the vertical line rules at the edges of a column and its content. This can be set as a keyword argument to the constructor or after instantiation using the set_padding_width method. The value is set to 1 by defaut. If your table is too wide for a small screen with this value, setting it to 0 might help you squeeze it in.
Thanks to Chris Clark for contributing a patch against 0.2.1 to add this feature!
PrettyTable 0.2.1 - April 29, 2009 (Download) (Webpage)
This is a bug fix release to take care of some serious problems in 0.2, which was obviously released with insufficient testing!
- Caching no longer breaks when using the printt(fields=[...]) syntax. The list of fields was not hashable and hence could not be used as a dictionary key. I fixed this using the output of the cPickle module's dumps function as the dictionary key instead.
- Horizontal lines are now the appropriate length when the above syntax is used.
Thanks to Julien Koesten for reporting these bugs and testing the fixes almost immediately after the release of 0.2!
PrettyTable 0.2 - April 29, 2009 (Download) (Webpage)
- Added get_string method.
- Added str method (which just calls get_string) to enable nice print x syntax.
- Can now pass field names as a constructor argument.
- Return values of get_string are cached in a dictionary that is only cleared after a call to add_row or something else which invalidates the cache.