5.2. Table Writer Factory

class pytablewriter.TableWriterFactory

Bases: object

A factor class of table writer classes.

classmethod create_from_file_extension(file_extension)

Create a table writer class instance from a file extension. Supported file extensions are as follows:

Extension Writer Class
".csv" CsvTableWriter
".htm" HtmlTableWriter
".html" HtmlTableWriter
".js" JavaScriptTableWriter
".json" JsonTableWriter
".jsonl" JsonLinesTableWriter
".ltsv" LtsvTableWriter
".ldjson" JsonLinesTableWriter
".md" MarkdownTableWriter
".ndjson" JsonLinesTableWriter
".py" PythonCodeTableWriter
".rst" RstGridTableWriter
".tsv" TsvTableWriter
".xls" ExcelXlsTableWriter
".xlsx" ExcelXlsxTableWriter
".sqlite" SqliteTableWriter
".sqlite3" SqliteTableWriter
".tsv" TsvTableWriter
".toml" TomlTableWriter
Parameters:file_extension (str) – File extension string (case insensitive).
Returns:Writer instance that coincides with the file_extension.
Return type:TableWriterInterface
Raises:pytablewriter.WriterNotFoundError – If an appropriate writer not found for the file extension.
classmethod create_from_format_name(format_name)

Create a table writer class instance from a format name. Supported file format names are as follows:

Format name Writer Class
"csv" CsvTableWriter
"elasticsearch" ElasticsearchWriter
"excel" ExcelXlsxTableWriter
"html"/"htm" HtmlTableWriter
"javascript"/"js" JavaScriptTableWriter
"json" JsonTableWriter
"json_lines" JsonLinesTableWriter
"latex_matrix" LatexMatrixWriter
"latex_table" LatexTableWriter
"ldjson" JsonLinesTableWriter
"ltsv" LtsvTableWriter
"markdown"/"md" MarkdownTableWriter
"mediawiki" MediaWikiTableWriter
"null" NullTableWriter
"pandas" PandasDataFrameWriter
"py"/"python" PythonCodeTableWriter
"rst"/"rst_grid"/"rst_grid_table" RstGridTableWriter
"rst_simple"/"rst_simple_table" RstSimpleTableWriter
"rst_csv"/"rst_csv_table" RstCsvTableWriter
"sqlite" SqliteTableWriter
"tsv" TsvTableWriter
"toml" TomlTableWriter
Parameters:format_name (str) – Format name string (case insensitive).
Returns:Writer instance that coincides with the format_name:
Return type:TableWriterInterface
Raises:pytablewriter.WriterNotFoundError – If an appropriate writer not found for for the format.
classmethod get_extension_list()
Returns:

Available file extensions.

Return type:

list

Example:
>>> import pytablewriter as ptw
>>> for name in ptw.TableWriterFactory.get_extension_list():
...     print(name)
...
csv
htm
html
js
json
ltsv
md
py
rst
sqlite
sqlite3
tex
toml
tsv
xls
xlsx
classmethod get_format_name_list()
Returns:

Available format names.

Return type:

list

Example:
>>> import pytablewriter as ptw
>>> for name in ptw.TableWriterFactory.get_format_name_list():
...     print(name)
...
csv
elasticsearch
excel
htm
html
javascript
js
json
latex_matrix
latex_table
ltsv
markdown
md
mediawiki
null
numpy
pandas
py
python
rst
rst_csv_table
rst_grid_table
rst_simple_table
sqlite
toml
tsv