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) AbstractTableWriter [source]¶
Create a table writer class instance from a file extension. Supported file extensions are as follows:
Extension
Writer Class
".adoc"
".asciidoc"
".asc"
".css"
".csv"
".htm"
".html"
".js"
".json"
".jsonl"
".ltsv"
".ldjson"
".md"
".ndjson"
".py"
".rst"
".tsv"
".xls"
".xlsx"
".sqlite"
".sqlite3"
".tsv"
".toml"
".yml"
- 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) AbstractTableWriter [source]¶
Create a table writer class instance from a format name. Supported file format names are as follows:
Format name
Writer Class
"adoc"
"asciidoc"
"css"
"csv"
"elasticsearch"
"excel"
"html"
/"htm"
"javascript"
/"js"
"json"
"json_lines"
"latex_matrix"
"latex_table"
"ldjson"
"ltsv"
"markdown"
/"md"
"mediawiki"
"null"
NullTableWriter
"pandas"
"py"
/"python"
"rst"
/"rst_grid"
/"rst_grid_table"
"rst_simple"
/"rst_simple_table"
"rst_csv"
/"rst_csv_table"
"sqlite"
"ssv"
"tsv"
"toml"
"unicode"
"yaml"
- 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) ... adoc asc asciidoc 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) ... adoc asciidoc bold_unicode borderless 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 pandas_pickle py python rst rst_csv rst_csv_table rst_grid rst_grid_table rst_simple rst_simple_table space_aligned sqlite ssv toml tsv unicode yaml