Skip to main content

A class for drawing table in text console for python in windows or linux

Project description

TextTable

TextTable is a lightweight Python module that helps developers draw well-formatted tables in the console using ASCII or Unicode box-drawing characters.

It is designed for command-line applications where clear tabular output and optional pagination are required.


Features

  • Draw tables using ASCII or Unicode borders
  • Support for single-line, double-line, and dashed table styles
  • Automatic column width calculation
  • Left, right, and center text alignment
  • Pagination support for large datasets
  • Cross-platform (Windows, Linux, macOS)

Installation

pip install pytexttable

Basic Usage

from TextTable import TextTable,Alignment
#type could be - or = or + to show table with different line style
t = TextTable(ttype='=', page_size=10)
t.set_columns(['Column 1', 'Column 2', 'Column 3'])
t.head_align = [Alignment.center,Alignment.left,Alignment.right]
t.cell_align = [Alignment.left,Alignment.center,Alignment.right]
t.add_row(['Data 1', 'Data 2', 'Data 3'])
t.add_row(['More', 'Sample', 'Values'])
#Setting columns width(charachter counts) is optional since TextTable compute column width based on the length of data and column name
t.columnsw = [30,20,15]
print(t)
output:
╔══════════════════════════════╦════════════════════╦═══════════════╗
║           Column 1           ║Column 2            ║       Column 3║
╠══════════════════════════════╬════════════════════╬═══════════════╣
║Data 1                        ║       Data 2       ║         Data 3║
║More                          ║       Sample       ║         Values║
╚══════════════════════════════╩════════════════════╩═══════════════╝

Pagination Example

from TextTable import TextTable
t = TextTable(ttype='-', page_size=5)
t.set_columns(['ID', 'Name', 'Value'])
for i in range(20):
    t.add_row([str(i), f'Item {i}', str(i * 10)])
t.print_with_pagination()
output:
┌──┬───────┬─────┐
│ID│Name   │Value│
├──┼───────┼─────┤
│10│Item 10│100  │
│11│Item 11│110  │
│12│Item 12│120  │
│13│Item 13│130  │
│14│Item 14│140  │
└──┴───────┴─────┘

Use keyboard input to navigate:

1 or right/up arrow → Next page

2 or left/down arrow → Previous page

0 / Enter → Exit

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

pytexttable-0.1.5.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

pytexttable-0.1.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pytexttable-0.1.5.tar.gz.

File metadata

  • Download URL: pytexttable-0.1.5.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pytexttable-0.1.5.tar.gz
Algorithm Hash digest
SHA256 6c8f2f632f9ee13e5abf6c69d8196aa27dce7e5051b2e762315a46b65652ee6e
MD5 b9c9204f958e7bfaae27eba7f0bc1e2f
BLAKE2b-256 c4b53f61607e0f2bca51e628bcc05261aa302a5ea1da7faaa85696513aadc47a

See more details on using hashes here.

File details

Details for the file pytexttable-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pytexttable-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pytexttable-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2206d3506b88c0c2e35b9dfe1bfc960996f6dd79d4a802a7ba3b42648f193922
MD5 021b0a0768525b9ae15604e158665a4f
BLAKE2b-256 5966c699563c50be3c83f109386103980f1a8fd9a5dd51b2aeff14252f6e2446

See more details on using hashes here.

Supported by

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