Install & Compatibility
Where this runs
tested against v1.2.1 · 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
muslpy 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 14.103s · 40.8MB
glibcpy 3.10–3.915 runs
installs and imports cleanly · install 8.7s · import 11.561s · 41MB
43MB installed
● package 43MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MarkdownTableWriter
✓ from pytablewriter import MarkdownTableWriter
CsvTableWriter
✓ from pytablewriter import CsvTableWriter
Import specific writer classes directly for different output formats.
TableWriterFactory
✓ from pytablewriter import TableWriterFactory
Use the factory to create writers dynamically based on format name.
This example demonstrates how to create and write a simple Markdown table to standard output using `MarkdownTableWriter`. It also shows how to use the `TableWriterFactory` to dynamically create a writer for a specified format, such as HTML. The `output_stream` is set to `sys.stdout` for direct console output, though it can also be a file object or `io.StringIO` to capture the output as a string.
import pytablewriter as ptw
import sys
# Create a MarkdownTableWriter instance
writer = ptw.MarkdownTableWriter(
table_name="example_table",
headers=["int", "float", "str", "bool", "mix", "time"],
value_matrix=[
[0, 0.1, "hoge", True, 0, "2017-01-01 03:04:05+0900"],
[2, "-2.23", "foo", False, None, "2017-12-23 45:01:23+0900"],
[3, 0, "bar", "true", "inf", "2017-03-03 33:44:55+0900"],
[-10, -9.9, "", "FALSE", "nan", "2017-01-01 00:00:00+0900"],
],
output_stream=sys.stdout # Direct output to stdout
)
# Write the table
writer.write_table()
print("\n--- Using TableWriterFactory ---")
# Alternatively, use the factory to create a writer
writer_from_factory = ptw.TableWriterFactory.create_from_format_name(
"html",
headers=["Key", "Value"],
value_matrix=[["API_KEY", "***"], ["Endpoint", "https://example.com/api"]],
output_stream=sys.stdout # Direct output to stdout
)
writer_from_factory.write_table()
pytablewriter --version
Debug
Known issues
breakingPython 3.7 and 3.8 are no longer supported as of `pytablewriter` v1.2.1. Python 3.6 was dropped in v1.0.0. Ensure your Python environment is 3.9 or higher.fixUpgrade your Python interpreter to version 3.9 or newer.
affects: >=1.2.1 (for 3.7-3.8 drop), >=1.0.0 (for 3.6 drop)
breakingSupport for Elasticsearch 7 was dropped in `pytablewriter` v1.0.0. If you are using the Elasticsearch writer, you must upgrade your Elasticsearch instance to version 8 or later.fixUpgrade Elasticsearch to version 8 or higher, or downgrade `pytablewriter` to a version prior to 1.0.0 if legacy ES7 support is critical.
affects: >=1.0.0
gotchaMany table formats (e.g., Excel, Pandas, Elasticsearch, SQLite, TOML, specific themes) require additional dependencies that are not installed by default. These are provided as 'extras' for `pip install`.fixInstall `pytablewriter` with the necessary extras, e.g., `pip install pytablewriter[excel,pandas]` or `pip install pytablewriter[all]`.
affects: All versions
gotchaThe `Cell` class became immutable in `pytablewriter` v1.0.0. Direct modification of `Cell` objects after creation is no longer possible.fixReconstruct `Cell` objects or update table data through the writer's `value_matrix` if you need to change cell values.
affects: >=1.0.0
gotchaTheme plugins, such as `pytablewriter-altrow-theme`, require a separate installation via `pip install pytablewriter[theme]`. Simply specifying a theme name in the writer constructor without the plugin will result in a `RuntimeError`.fixEnsure the `pytablewriter[theme]` extra is installed if you intend to use specific themes.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytablewriter'
The pytablewriter package is not installed in the current Python environment.
fixpip install pytablewriter
ImportError: cannot import name 'TableWriter' from 'pytablewriter'
Attempting to import a non-existent generic 'TableWriter' class directly from the pytablewriter package, instead of a specific format writer (e.g., MarkdownTableWriter).
fixfrom pytablewriter import MarkdownTableWriter
TypeError: value_matrix must be a list or tuple.
The 'value_matrix' attribute was assigned a value that is not a list of lists or a tuple of tuples, violating its expected type.
fixwriter.value_matrix = [['data1', 1], ['data2', 2]]
AttributeError: 'MarkdownTableWriter' object has no attribute 'write'
Attempting to call a method named 'write()' which does not exist on pytablewriter writer objects; the correct method for writing the table is 'write_table()'.
Upgrade
Version history
1.2.1latest on PyPI · released Jan 1, 2025
Audit
Dependencies
DataPropertyrequiredCore dependency, minimum version bumped to 1.1.0 in v1.2.1.
typepyrequiredCore dependency, minimum version bumped to 1.3.2 in v1.2.0.
pathvalidaterequiredCore dependency, updated to allow v3+ in v1.0.0.
SimpleSQLiterequiredCore dependency for SQLite writer, minimum version bumped in v1.0.0.
pandasrequiredOptional, required for writing from/to Pandas DataFrames. Install with `pytablewriter[pandas]` extra.
openpyxlrequiredOptional, required for Excel (.xlsx) output. Install with `pytablewriter[excel]` extra.
elasticsearchrequiredOptional, required for Elasticsearch output. Install with `pytablewriter[es]` extra.
PyYAMLrequiredOptional, for YAML output, supports v7+ from v0.64.2. Install with `pytablewriter[yaml]` extra.