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

Uploaded Source

Built Distribution

termtables-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: termtables-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.5.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for termtables-0.1.1.tar.gz
Algorithm Hash digest
SHA256 762ba718cae224917fd8e1eda5cbfb33027ab6c86cfb9dd676e35f0c6516b4bf
MD5 860c483649768c1ca9cd935c100ab05f
BLAKE2b-256 25830b9ea67a2b5623f41c3b905e4d7024702e8110200071c1b2d8fdec7450ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: termtables-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.5.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for termtables-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0fd321f7f478001f824896b4dbc5af0cf296ecf3c4aa450018cdcd31b4880b6e
MD5 1dc494be4435e0ad3073b0caf6c263a8
BLAKE2b-256 db18c414bfd40694d79c88fc5d7fe2cd7dbe0805aae644ded248108999c0bc83

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