Registry / serialization / texttable

texttable

JSON →
library1.7.0pypypi✓ verified 26d ago

Texttable is a Python module to create simple ASCII tables. It provides an easy-to-use API for formatting data into human-readable text tables, supporting various alignments, data types, and decorative options. The current version is 1.7.0, and it is actively maintained with regular updates.

pip install texttable
INSTALL
IMPORT
SIG · TEXTTABLE
T
texttable
serializationpythonv1.7.0
Install
1.5s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.008s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.006s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Texttable
from texttable import Texttable

This quickstart demonstrates how to create a basic ASCII table, set column alignments and data types, add a header, and populate it with data before printing.

from texttable import Texttable table = Texttable() # Set column alignments (left, right, center) table.set_cols_align(["l", "r", "c"]) # Set column data types (text, float, integer) table.set_cols_dtype(["t", "f", "i"]) # Add a header row table.header(["Name", "Score", "Rank"]) # Add rows of data table.add_row(["Alice", 95.5, 1]) table.add_row(["Bob", 88.0, 2]) table.add_row(["Charlie", 72.3, 3]) # Draw and print the table print(table.draw())
Debug
Known issues
gotchaAutomatic column data type detection can lead to unexpected formatting, especially for numbers like `1.0` or `0.0` which might be converted to integers instead of floats. Always explicitly set column data types using `set_cols_dtype()` if precise formatting is needed.
fix
Call `table.set_cols_dtype(['t', 'f', 'i', 'a'])` before adding rows to define how each column's data should be handled (text, float, integer, auto).
affects: All versions
gotchaThe `max_width` parameter in the `Texttable` constructor can cause cell content to wrap if the content exceeds the calculated column width. Setting `max_width=0` allows the table to self-adjust and prevents wrapping, ensuring all content appears on a single line where possible.
fix
Initialize `Texttable` with `table = Texttable(max_width=0)` for a dynamically sized table, or carefully manage `max_width` if wrapping is desired.
affects: All versions
breakingVersion 1.6.5 introduced a regression where stub files were missing in the wheel package, potentially causing import or packaging issues for some users.
fix
Upgrade to version 1.6.6 or later, which includes a fix for this regression.
affects: 1.6.5
deprecatedThe behavior of boolean values in table cells was improved with a dedicated formatting option in version 1.7.0. Older versions might not format booleans as intuitively or consistently.
fix
Upgrade to version 1.7.0 or newer to leverage the enhanced boolean formatting capabilities.
affects: <1.7.0
Errors
Common errors & fixes
IndexError: list index out of range
This error occurs when `add_row()` is called with a number of cells that does not match the implicitly or explicitly defined number of columns for the table.
fix
Ensure each list passed to `add_row()` contains the same number of elements as the table's total column count, which is often determined by the first row added or methods like `set_cols_align`.
TypeError: set_cols_dtype() takes 2 positional arguments but X were given
The `set_cols_dtype` method expects a single iterable (list or tuple) containing type codes as its `dtypes` argument, not separate arguments for each column.
fix
Pass a list or tuple of type codes to `set_cols_dtype`, even if defining the type for only one column, e.g., `table.set_cols_dtype(['t', 'f'])`.
ValueError: Unknown type specified for column
An invalid character or unsupported type code was provided in the list of data types for the `set_cols_dtype` method.
fix
Use one of the supported type codes: 't' (text), 'f' (float), 'e' (scientific), 'i' (integer), 'a' (auto), 'd' (date).
ImportError: cannot import name 'texttable' from 'texttable'
The main class in the `texttable` library is named `Texttable` (with a capital 'T'), but the import statement attempted to use a lowercase 't'.
fix
Correct the capitalization in the import statement: `from texttable import Texttable`.
Upgrade
Version history
1.7.0latest on PyPI · released Oct 3, 2023
Audit
Dependencies
cjkwrapoptionalUsed for better wrapping of CJK text.
wcwidthoptionalUsed for better rendering, including basic emoji support.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
texttable — pip install texttable · libregistry