5.2. Table Writer Factory

class pytablewriter.TableWriterFactory[source]

Bases: object

A factor class of table writer classes.

classmethod create_from_file_extension(file_extension)[source]

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

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)[source]

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
"unicode" UnicodeTableWriter
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_extensions()[source]
Returns:

Available file extensions.

Return type:

list

Example:
>>> import pytablewriter as ptw
>>> for name in ptw.TableWriterFactory.get_extensions():
...     print(name)
...
csv
htm
html
js
json
jsonl
ldjson
ltsv
md
ndjson
py
rst
sqlite
sqlite3
tex
toml
tsv
xls
xlsx
classmethod get_format_names()[source]
Returns:

Available format names.

Return type:

list

Example:
>>> import pytablewriter as ptw
>>> for name in ptw.TableWriterFactory.get_format_names():
...     print(name)
...
csv
elasticsearch
excel
htm
html
javascript
js
json
json_lines
jsonl
latex_matrix
latex_table
ldjson
ltsv
markdown
md
mediawiki
ndjson
null
numpy
pandas
py
python
rst
rst_csv
rst_csv_table
rst_grid
rst_grid_table
rst_simple
rst_simple_table
space_aligned
sqlite
toml
tsv
unicode