Metadata-Version: 2.1
Name: plaintable
Version: 0.1.1
Summary: A simple library to build plain text tables
Home-page: https://github.com/rumpelsepp/plaintable
Author: Stefan Tatschner
Author-email: stefan@sevenbyte.org
License: MIT
Keywords: table development
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
License-File: LICENSE

plaintable
==========

Plaintable is a very simple library to build plain text tables. It has been
created to provide a very lightweight and clear interface for generating plain
text tables. Some data can be customized e.g. alignment, padding and
floatprecision. Every data item is to be converted to string automatically.


Usage
-----

.. code-block:: pycon

    >>> from plaintable import Table
    >>> data = [
    ...     [1, 2, 3, 4, 5],
    ...     [10, 11, 12, 13, 14],
    ...     ['a', 'b', 'c', 'd', 'e'],
    ...     [1.0, 2.0, 1.5, 4.25, 10.50],
    ... ]
    >>> headline = ['one', 'two', 'three', 'four', 'five']
    >>> table = Table(data, headline)
    >>> print(table)
    one   two   three  four  five
    ----  ----  -----  ----  -----
    1     2     3      4     5
    10    11    12     13    14
    a     b     c      d     e
    1.00  2.00  1.50   4.25  10.50


Customise
---------

The table layout can be customised by passing several keyword arguments
to ``Table.__init__()``.

headline
    A list of strings which will appear as column headers. This argument
    is optional.

    **Default: None**
align
    You can specifiy the alignment of the table ('l', 'r', 'c').

    **Default: 'l'**
padding
    If you need a wider table you can increase the padding.

    **Default: 2**
floatprec
    Every float value is converted to ``str`` with this precision.

    **Default: 2**
header_padding
    Adds extra spaces around header fields.

    **Default: 0**
datetimefs
    Specifies the datetime formatstring. Any datetime object is converted
    to a string refering to this formatstring; see also here_.

    **Default:** ``%Y-%m-%d %H:%M``

.. _here: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior


Further Examples
----------------

.. code-block:: pycon

    >>> from plaintable import Table
    >>> data = [
    ...    [1, 2, 3, 4, 5],
    ...    [10, 11, 12, 13, 14],
    ...    ['a', 'b', 'c', 'd', 'e'],
    ...    [1.0, 2.0, 1.5, 4.25, 10.50],
    ... ]
    >>> headline = ['one', 'two', 'three', 'four', 'five']
    >>> table = Table(data, headline, align='r', padding=4, floatprec=4)
    >>> print(table)
           one       two     three      four       five
        ------    ------    ------    ------    -------
             1         2         3         4          5
            10        11        12        13         14
             a         b         c         d          e
        1.0000    2.0000    1.5000    4.2500    10.5000


.. code-block:: pycon

    >>> from plaintable import Table
    >>> data = [
    ...    [1, 2, 3, 4, 5],
    ...    [10, 11, 12, 13, 14],
    ...    ['a', 'b', 'c', 'd', 'e'],
    ...    [1.0, 2.0, 1.5, 4.25, 10.50],
    ... ]
    >>> table = Table(data)
    >>> print(table)
    1     2     3     4     5
    10    11    12    13    14
    a     b     c     d     e
    1.00  2.00  1.50  4.25  10.50


.. code-block:: pycon

    >>> from plaintable import Table
    >>> data = [
    ...    [1, 2, 3, 4, 5],
    ...    [10, 11, 12, 13, 14],
    ...    ['a', 'b', 'c', 'd', 'e'],
    ...    [1.0, 2.0, 1.5, 4.25, 10.50],
    ... ]
    >>> table = Table(data, padding=4)
    >>> print(table)
    1       2       3       4
    10      11      12      13
    a       b       c       d
    1.00    2.00    1.50    4.25


.. code-block:: pycon

    >>> from plaintable import Table
    >>> data = [
    ...    [1, 2, 3, 4, 5],
    ...    [10, 11, 12, 13, 14],
    ...    ['a', 'b', 'c', 'd', 'e'],
    ...    [1.0, 2.0, 1.5, 4.25, 10.50],
    ... ]
    >>> table = Table(data, header_padding=4)
    >>> print(table)
    one          two          three          four
    -----------  -----------  -------------  ------------
    1            2            3              4
    10           11           12             13
    a            b            c              d
    1.00         2.00         1.50           4.25
