Skip to main content

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

Other software for terminal tables

License

This software is published under the GPL-3.0 license.

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.4.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

termtables-0.2.4-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: termtables-0.2.4.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.2.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.4

File hashes

Hashes for termtables-0.2.4.tar.gz
Algorithm Hash digest
SHA256 797c6afeb78abdab97cd5bfbbd2fc1bfbd9630052699dc881b27b334bcc6a73f
MD5 9a858e608132c52ecfd20eb7bff1ed15
BLAKE2b-256 8635b2a0e5abf04e219c92cdc35af72dfcd157c1f43fda538adc282b34a26357

See more details on using hashes here.

File details

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

File metadata

  • Download URL: termtables-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.2.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.4

File hashes

Hashes for termtables-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0ca860eed8957db0045020bcdfcf6620e188b0d776e8543a57ff539fcfeec26d
MD5 b141aab3d4ad9bc298b0406ed7f5c43d
BLAKE2b-256 f951e56764d0db7ec7b2eb121749e6521a53697e8c1cd55a9d0e4374dd587543

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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