Skip to main content

Pretty tables in the terminal

Project description

termtables

The tables have termed.

gh-actions codecov Code style: black awesome PyPI pyversions PyPi Version GitHub stars PyPi downloads

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

Uploaded Source

Built Distribution

termtables-0.2.1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: termtables-0.2.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for termtables-0.2.1.tar.gz
Algorithm Hash digest
SHA256 27415e8835917465a61a5af42d0acb1e37fbdb8bd7ea2b376abc984c0db8b57f
MD5 6984847634399c8069352fdbf2fec223
BLAKE2b-256 64ea6ae0e77149ce43321a56f07e40c6bda3cafaa7fc3c01b1da53353b5efe6c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: termtables-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for termtables-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53c9e5b9d41e25c08ee9816afd4d37858b774f67fe9f63092e7a77acec3946e4
MD5 ca44ce8ef2c339e75338c61a75f5bd4c
BLAKE2b-256 51d3cb7f1d5d93c9b7fcaa06fd1dfbe09f01d3cfc3f847187829cb995be82ff1

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