Skip to content
Pretty tables in the terminal
Python Makefile
Branch: master
Clone or download
Latest commit 5508afa Sep 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci add gh-actions config Sep 26, 2019
.github/workflows gh-actions: don't submit to codecov yet Sep 26, 2019
termtables version bump Jul 7, 2019
test test coverage Jul 7, 2019
.flake8 add .flake8 config Jul 6, 2019
.gitignore add gh-actions config Sep 26, 2019
CODE_OF_CONDUCT.md initial commit Jul 6, 2019
CONTRIBUTING.md
LICENSE initial commit Jul 6, 2019
Makefile add gh-actions config Sep 26, 2019
README.md add gh-actions config Sep 26, 2019
codecov.yml initial commit Jul 6, 2019
setup.py
test-requirements.txt rename file Jul 6, 2019

README.md

termtables

The tables have termed.

CircleCI codecov Code style: black awesome PyPi Version GitHub stars PyPi downloads

termtables is a lightweight Python package for pretty-printing tables on the command line. Install with

pip3 install termtables --user

The code

import termtables as tt
import numpy

numpy.random.seed(0)
data = numpy.random.rand(5, 2)

print(tt.to_string(data))

produces

table1

You can control border style, padding, alignment, and various other attributes. For example,

import termtables as tt

header = ["a", "bb", "ccc"]
data = [
    [1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]
]

string = tt.to_string(
    data,
    header=header,
    style=tt.styles.ascii_thin_double,
    padding=(0, 1),
    alignment="lcr"
)
print(string)

produces

+-----------------+-----------------+-----------------+
| a               |       bb        |             ccc |
+=================+=================+=================+
| 1               |        2        |               3 |
+-----------------+-----------------+-----------------+
| 613.23236243236 | 613.23236243236 | 613.23236243236 |
+-----------------+-----------------+-----------------+

See test/test_termtables.py for more examples.

If the styles in termtables.styles

thin
thin_thick
thin_double
rounded
rounded_thick
rounded_double
thick
thick_thin
double
double_thin
booktabs

ascii_thin
ascii_thin_double
ascii_double
ascii_double_thin
ascii_booktabs

aren't good enough for you, simply provide your own style as a string of length 11 or 15 (the extra 4 including header-separating characters). For example

import termtables as tt

header = ["a", "bb", "ccc"]
data = [
    [1, 2, 3], [613.23236243236, 613.23236243236, 613.23236243236]
]

string = tt.to_string(
    data,
    header=header,
    style="x0123456789abcd"
)
print(string)

produces

1xxxxxxxxxxxxxxxxx7xxxxxxxxxxxxxxxxx7xxxxxxxxxxxxxxxxx2
0 a               0 bb              0 ccc             0
abbbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbbbd
0 1               0 2               0 3               0
5xxxxxxxxxxxxxxxxx9xxxxxxxxxxxxxxxxx9xxxxxxxxxxxxxxxxx6
0 613.23236243236 0 613.23236243236 0 613.23236243236 0
3xxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxx4

Testing

To run the termtables unit tests, check out this repository and type

pytest

License

termtables is published under the MIT license.

You can’t perform that action at this time.