{"id":2718,"library":"pytablewriter","title":"PyTableWriter","description":"pytablewriter is a Python library (current version 1.2.1) designed to efficiently write tabular data into a wide array of formats, including AsciiDoc, CSV, Elasticsearch, HTML, JavaScript, JSON, LaTeX, Markdown, MediaWiki, NumPy, Excel, Pandas, Python, reStructuredText, SQLite, TOML, TSV, and YAML. It maintains an active development pace with frequent minor and patch releases, ensuring broad compatibility and feature enhancements.","status":"active","version":"1.2.1","language":"en","source_language":"en","source_url":"https://github.com/thombashi/pytablewriter","tags":["table","export","markdown","csv","excel","html","json","latex","restructuredtext","sqlite","yaml","data-conversion","formatting"],"install":[{"cmd":"pip install pytablewriter","lang":"bash","label":"Basic Installation"},{"cmd":"pip install pytablewriter[all]","lang":"bash","label":"All Optional Dependencies"},{"cmd":"pip install pytablewriter[excel] pytablewriter[pandas]","lang":"bash","label":"Specific Optional Dependencies (e.g., Excel and Pandas)"}],"dependencies":[{"reason":"Core dependency, minimum version bumped to 1.1.0 in v1.2.1.","package":"DataProperty"},{"reason":"Core dependency, minimum version bumped to 1.3.2 in v1.2.0.","package":"typepy"},{"reason":"Core dependency, updated to allow v3+ in v1.0.0.","package":"pathvalidate"},{"reason":"Core dependency for SQLite writer, minimum version bumped in v1.0.0.","package":"SimpleSQLite"},{"reason":"Optional, required for writing from/to Pandas DataFrames. Install with `pytablewriter[pandas]` extra.","package":"pandas"},{"reason":"Optional, required for Excel (.xlsx) output. Install with `pytablewriter[excel]` extra.","package":"openpyxl"},{"reason":"Optional, required for Elasticsearch output. Install with `pytablewriter[es]` extra.","package":"elasticsearch"},{"reason":"Optional, for YAML output, supports v7+ from v0.64.2. Install with `pytablewriter[yaml]` extra.","package":"PyYAML"}],"imports":[{"symbol":"MarkdownTableWriter","correct":"from pytablewriter import MarkdownTableWriter"},{"note":"Import specific writer classes directly for different output formats.","symbol":"CsvTableWriter","correct":"from pytablewriter import CsvTableWriter"},{"note":"Use the factory to create writers dynamically based on format name.","symbol":"TableWriterFactory","correct":"from pytablewriter import TableWriterFactory"}],"quickstart":{"code":"import pytablewriter as ptw\nimport sys\n\n# Create a MarkdownTableWriter instance\nwriter = ptw.MarkdownTableWriter(\n    table_name=\"example_table\",\n    headers=[\"int\", \"float\", \"str\", \"bool\", \"mix\", \"time\"],\n    value_matrix=[\n        [0, 0.1, \"hoge\", True, 0, \"2017-01-01 03:04:05+0900\"],\n        [2, \"-2.23\", \"foo\", False, None, \"2017-12-23 45:01:23+0900\"],\n        [3, 0, \"bar\", \"true\", \"inf\", \"2017-03-03 33:44:55+0900\"],\n        [-10, -9.9, \"\", \"FALSE\", \"nan\", \"2017-01-01 00:00:00+0900\"],\n    ],\n    output_stream=sys.stdout # Direct output to stdout\n)\n\n# Write the table\nwriter.write_table()\n\nprint(\"\\n--- Using TableWriterFactory ---\")\n# Alternatively, use the factory to create a writer\nwriter_from_factory = ptw.TableWriterFactory.create_from_format_name(\n    \"html\",\n    headers=[\"Key\", \"Value\"],\n    value_matrix=[[\"API_KEY\", \"***\"], [\"Endpoint\", \"https://example.com/api\"]],\n    output_stream=sys.stdout # Direct output to stdout\n)\nwriter_from_factory.write_table()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python interpreter to version 3.9 or newer.","message":"Python 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.","severity":"breaking","affected_versions":">=1.2.1 (for 3.7-3.8 drop), >=1.0.0 (for 3.6 drop)"},{"fix":"Upgrade Elasticsearch to version 8 or higher, or downgrade `pytablewriter` to a version prior to 1.0.0 if legacy ES7 support is critical.","message":"Support 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Install `pytablewriter` with the necessary extras, e.g., `pip install pytablewriter[excel,pandas]` or `pip install pytablewriter[all]`.","message":"Many 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`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Reconstruct `Cell` objects or update table data through the writer's `value_matrix` if you need to change cell values.","message":"The `Cell` class became immutable in `pytablewriter` v1.0.0. Direct modification of `Cell` objects after creation is no longer possible.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the `pytablewriter[theme]` extra is installed if you intend to use specific themes.","message":"Theme 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`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}