Skip to main content

Pretty tables in the terminal

Project description

termtables

The tables have termed.

PyPi Version PyPI pyversions GitHub stars PyPi downloads

gh-actions codecov LGTM Code style: black

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

pip install termtables

The code

import termtables as tt
import numpy

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

tt.print(data)
# tt.to_string(data) returns the string

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]
]

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

produces

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

which is useful for copy-pasting into websites that support Markdown (like GitHub).

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

markdown

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]
]

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

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

tox

License

This software is published under the GPL-3.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termtables-0.2.3.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

termtables-0.2.3-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file termtables-0.2.3.tar.gz.

File metadata

  • Download URL: termtables-0.2.3.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.9.0rc1

File hashes

Hashes for termtables-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6c62e19e4d27a594ed53245b8d0ac5b818995a2eec571399bb4190c17d32df72
MD5 b1380d87ca816d4f0dfd982ff139df9f
BLAKE2b-256 e3f6fbb8ed497032f0576b341a04819e63fa3b1812a7e8ebd4d43be8be78ca32

See more details on using hashes here.

File details

Details for the file termtables-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: termtables-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.9.0rc1

File hashes

Hashes for termtables-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a5f422dd1c6aeb864b8b17cbab0847dd3c622365d2c7b4078cc2dfd8e9ec54f2
MD5 cd5bf29cc1947e8aa10bc77a2ca19de9
BLAKE2b-256 a6198a274482b1e3e74728bf932140dad8e5ff0e7b1217bd0c8f737bafaa8da7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page