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.ascii_thin_double,
    padding=(0, 1),
    alignment="lcr"
)

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

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

Uploaded Source

Built Distribution

termtables-0.2.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: termtables-0.2.0.tar.gz
  • Upload date:
  • Size: 7.3 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.0.tar.gz
Algorithm Hash digest
SHA256 9818dbdbd150a3571562a464252bbe4c9c6c0dcf157038c106519c66dfad0cca
MD5 609e91ae8f44a0644a6027c85b53cd28
BLAKE2b-256 55f2dffd2946f693ee7e3d398bc6514a7131689f242f3f541ac702c9bfaff1d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: termtables-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f77407955ebe74f5cf93742606cc6fbc9f725fda9e50bfc8f3198ba5cd39ba6
MD5 16ffde986b3e2ffeb152a475e7d0370d
BLAKE2b-256 2cde8daa8d5dd9951de2fd991d5b4220aae6f5b909410863d5b986080ea76d1b

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