5.2. Table Writer Factory

class pytablewriter.TableWriterFactory[source]

A factor class of table writer classes.

classmethod create_from_file_extension(file_extension: str, **kwargs)pytablewriter.writer._table_writer.AbstractTableWriter[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).

  • kwargs – Keyword arguments that passing to writer class constructor.

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: str, **kwargs)pytablewriter.writer._table_writer.AbstractTableWriter[source]

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

Format name

Writer Class

"css"

CssTableWriter

"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

"yaml"

YamlTableWriter

Parameters
  • format_name (str) – Format name string (case insensitive).

  • kwargs – Keyword arguments that passing to writer class constructor.

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()List[str][source]
Returns

Available file extensions.

Return type

list

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

Available format names.

Return type

list

Example
>>> import pytablewriter as ptw
>>> for name in ptw.TableWriterFactory.get_format_names():
...     print(name)
...
css
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
yaml