Skip to main content

Pretty tables in the terminal

Project description

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.

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

Uploaded Source

Built Distribution

termtables-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: termtables-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4rc2

File hashes

Hashes for termtables-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b01303c4f4e304d4c2fe4dc649a12ca50de48699aaace955fa7cb43fb030d9aa
MD5 f596e8d6d3f7f832ed27e9197141b008
BLAKE2b-256 80e8be3240251a96c58cab8e0d9a34cd71215c1abecb1481d5a9b79b71531617

See more details on using hashes here.

File details

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

File metadata

  • Download URL: termtables-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4rc2

File hashes

Hashes for termtables-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 517e49cb2012f3d763738d5a7cd30ca7de7fe2bdbff039e0a90a228f5d7b1ec9
MD5 9ed2ef25c78d72a1e2e8beb92b36be9f
BLAKE2b-256 9cea38af3736093336f7749e14da30f5517235f0d4e1ba380529b3118450ff50

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