5.1. Table Writer Classes

5.1.1. Text formats

5.1.1.1. CSV table writer classes

5.1.1.1.1. CSV writer

class pytablewriter.CsvTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.TextTableWriter

A table writer class for character separated values format. The default separated character is a comma (",").

Example:CSV
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.1.2. TSV writer

class pytablewriter.TsvTableWriter[source]

Bases: pytablewriter.writer.text._csv.CsvTableWriter

A table writer class for tab separated values (TSV) format.

Example:TSV
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.2. LTSV writer

class pytablewriter.LtsvTableWriter[source]

Bases: pytablewriter.writer.text._csv.CsvTableWriter

A table writer class for Labeled Tab-separated Values (LTSV) format.

Example:example-ltsv-table-writer
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()[source]

Write a table to the stream with Labeled Tab-separated Values (LTSV) format. Invalid characters in labels/data are removed.

Raises:pytablewriter.EmptyHeaderError – If the headers is empty.
Example:example-ltsv-table-writer
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.3. LaTeX writer classes

5.1.1.3.1. LaTeX matrix writer

class pytablewriter.LatexMatrixWriter[source]

Bases: pytablewriter.writer.text._latex.LatexWriter

A matrix writer class for LaTeX environment.

Example:LaTeX matrix
write_table()

Write a table to the stream with LaTeX array environment.

Example:LaTeX matrix
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.3.2. LaTeX table writer

class pytablewriter.LatexTableWriter[source]

Bases: pytablewriter.writer.text._latex.LatexWriter

A matrix writer class for LaTeX environment.

Example:LaTeX table
write_table()

Write a table to the stream with LaTeX array environment.

Example:LaTeX table
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.4. Markup language writer classes

5.1.1.4.1. HTML table writer

class pytablewriter.HtmlTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.TextTableWriter

A table writer class for HTML format.

Example:HTML
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()[source]

Write a table to the stream with HTML table format.

Example:HTML

Note

  • None is not written
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.4.2. MediaWiki table writer

class pytablewriter.MediaWikiTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.TextTableWriter

A table writer class for MediaWiki format.

Example:MediaWiki
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.4.3. Markdown table writer

class pytablewriter.MarkdownTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.IndentationTextTableWriter

A table writer class for Markdown format.

Example:Markdown
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()[source]

Write a table to the stream with Markdown table format.

Raises:pytablewriter.EmptyHeaderError – If the headers is empty.
Example:Markdown

Note

  • None values are written as an empty string
  • Vertical bar characters ('|') in table items are escaped
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.5. JSON writer class

class pytablewriter.JsonTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.IndentationTextTableWriter

A table writer class for JSON format.

Examples:JSON
write_table()

Write a table to the stream with JSON format.

Raises:pytablewriter.EmptyHeaderError – If the headers is empty.
Examples:JSON

Note

Specific values in the tabular data are converted when writing:

  • None: written as null
  • inf: written as Infinity
  • nan: written as NaN
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()[source]

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.6. Line-delimited JSON(LDJSON) writer class

class pytablewriter.JsonLinesTableWriter[source]

Bases: pytablewriter.writer.text._json.JsonTableWriter

A table writer class for JSON lines format.

Example:JSON lines
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()[source]

Write a table to the stream with Line-delimited JSON(LDJSON) /NDJSON/JSON Lines format.

Raises:pytablewriter.EmptyHeaderError – If the headers is empty.
Example:JSON lines
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.7. Source code writer classes

5.1.1.7.1. JavaScript writer

class pytablewriter.JavaScriptTableWriter[source]

Bases: pytablewriter.writer.text.sourcecode._sourcecode.SourceCodeTableWriter

A table writer for class JavaScript format.

Example:JavaScript Code
variable_declaration

JavaScript variable declarations type. The value must be either "var", "let" or "const". Defaults to "const".

write_table()

Write a table to the stream with JavaScript format. The tabular data are written as a nested list variable definition.

Raises:
Example:

JavaScript Code

Note

Specific values in the tabular data are converted when writing:

  • None: written as null
  • inf: written as Infinity
  • nan: written as NaN
  • datetime.datetime instances determined by is_datetime_instance_formatting attribute:
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

variable_name

Return a valid variable name that converted from the table_name.

Returns:A variable name.
Return type:str
write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.7.2. NumPy table writer

class pytablewriter.NumpyTableWriter[source]

Bases: pytablewriter.writer.text.sourcecode._python.PythonCodeTableWriter

A table writer class for NumPy source code format.

Example:NumPy array
write_table()

Write a table to the stream with NumPy format. The tabular data are written as a variable definition of numpy.array.

Raises:
Example:

NumPy array

Note

Specific values in the tabular data are converted when writing:

  • None: written as None
  • inf: written as numpy.inf
  • nan: written as numpy.nan
  • datetime.datetime instances determined by is_datetime_instance_formatting attribute:
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

variable_name

Return a valid variable name that converted from the table_name.

Returns:A variable name.
Return type:str
write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.7.3. Pandas DataFrame writer

class pytablewriter.PandasDataFrameWriter[source]

Bases: pytablewriter.writer.text.sourcecode._numpy.NumpyTableWriter

A writer class for Pandas DataFrame format.

import_pandas_as

Specify pandas module import name. Defaults to "pd".

import_numpy_as

Specify numpy module import name. Defaults to "np".

write_table()

Write a table to the stream with Pandas DataFrame format. The tabular data are written as a pandas.DataFrame class instance definition.

Raises:
Example:

Pandas DataFrame

Note

Specific values in the tabular data are converted when writing:

  • None: written as None
  • inf: written as numpy.inf
  • nan: written as numpy.nan
  • datetime.datetime instances determined by is_datetime_instance_formatting attribute:
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

variable_name

Return a valid variable name that converted from the table_name.

Returns:A variable name.
Return type:str
write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.7.4. Python table writer

class pytablewriter.PythonCodeTableWriter[source]

Bases: pytablewriter.writer.text.sourcecode._sourcecode.SourceCodeTableWriter

A table writer class for Python source code format.

Example:Python Code
write_table()

Write a table to the stream with Python format. The tabular data are written as a nested list variable definition for Python format.

Raises:
Example:

Python Code

Note

Specific values in the tabular data are converted when writing:

  • None: written as None
  • inf: written as float("inf")
  • nan: written as float("nan")
  • datetime.datetime instances determined by is_datetime_instance_formatting attribute:
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

variable_name

Return a valid variable name that converted from the table_name.

Returns:A variable name.
Return type:str
write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.8. reStructuredText writer classes

5.1.1.8.1. reStructuredText CSV table writer

class pytablewriter.RstCsvTableWriter[source]

Bases: pytablewriter.writer.text._rst.RstTableWriter

A table class writer for reStructuredText CSV table format.

close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()[source]

Write a table to the stream with reStructuredText CSV table format.

Raises:pytablewriter.EmptyTableDataError – If the headers and the value_matrix is empty.
Example:reStructuredText CSV Table

Note

  • None values are written as an empty string
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.8.2. reStructuredText grid table writer

class pytablewriter.RstGridTableWriter[source]

Bases: pytablewriter.writer.text._rst.RstTableWriter

A table writer class for reStructuredText Grid Tables format.

write_table()

Write a table to the stream with reStructuredText grid tables format.

Example:reStructuredText Grid Tables

Note

  • None values are written as an empty string
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.8.3. reStructuredText simple table writer

class pytablewriter.RstSimpleTableWriter[source]

Bases: pytablewriter.writer.text._rst.RstTableWriter

A table writer class for reStructuredText Simple Tables format.

write_table()

Write a table to the stream with reStructuredText simple tables format.

Example:reStructuredText Simple Tables

Note

  • None values are written as an empty string
close()

Close the current stream.

dec_indent_level()

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()

Increment the current indent level.

set_indent_level(indent_level)

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.9. Space aligned table writer

class pytablewriter.SpaceAlignedTableWriter[source]

Bases: pytablewriter.writer.text._csv.CsvTableWriter

A table writer class for space aligned format.

Example:example-space-aligned-table-writer
write_table()

Write a table to the stream with space aligned format.

Example:example-space-aligned-table-writer
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.1.10. TOML table writer class

class pytablewriter.TomlTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.TextTableWriter

A table writer class for TOML data format.

Example:TOML
close()

Close the current stream.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()[source]

Write a table to the stream with TOML format.

Raises:
Example:

TOML

write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.2. Binary formats

5.1.2.1. Excel writer classes

5.1.2.1.1. Xlsx table writer

class pytablewriter.ExcelXlsxTableWriter[source]

Bases: pytablewriter.writer.binary._excel.ExcelTableWriter

A table writer class for Excel file format: .xlsx (newer or equal to Office 2007).

write_table()

Write a table to the current opened worksheet.

Raises:IOError – If failed to write data to the worksheet.
Examples:Excel Sheet

Note

Specific values in the tabular data are converted when writing:

  • None: written as an empty string
  • inf: written as Inf
  • nan: written as NaN
close()

Close the current workbook.

dump(output, close_after_write=True)

Write a worksheet to the current workbook.

Parameters:
  • output (str) – Path to the workbook file to write.
  • close_after_write (bool, optional) – Close the workbook after write. Defaults to True.
first_data_col

Index of the first column of the table. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
first_data_row

Index of the first row of the data (table body). :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
first_header_row

Index of the first row of the header. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set following attributes from TableData

And create worksheet named from table_name ABC if not existed yet.

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

last_data_col

Index of the last column of the table. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
last_data_row

Index of the last row of the data (table body). :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
last_header_row

Index of the last row of the header. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
make_worksheet(sheet_name=None)

Make a worksheet to the current workbook.

Parameters:sheet_name (str) – Name of the worksheet to create. The name will be automatically generated (like "Sheet1") if the sheet_name is empty.
open(file_path)

Open an Excel workbook file.

Parameters:file_path (str) – Excel workbook file path to open.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_table()

Write a table to the stream.

write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.2.1.2. Xls table writer

class pytablewriter.ExcelXlsTableWriter[source]

Bases: pytablewriter.writer.binary._excel.ExcelTableWriter

A table writer class for Excel file format: .xls (older or equal to Office 2003).

xlwt package required to use this class.

write_table()

Write a table to the current opened worksheet.

Raises:IOError – If failed to write data to the worksheet.

Note

Specific values in the tabular data are converted when writing:

  • None: written as an empty string
  • inf: written as Inf
  • nan: written as NaN
close()

Close the current workbook.

dump(output, close_after_write=True)

Write a worksheet to the current workbook.

Parameters:
  • output (str) – Path to the workbook file to write.
  • close_after_write (bool, optional) – Close the workbook after write. Defaults to True.
first_data_col

Index of the first column of the table. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
first_data_row

Index of the first row of the data (table body). :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
first_header_row

Index of the first row of the header. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set following attributes from TableData

And create worksheet named from table_name ABC if not existed yet.

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

last_data_col

Index of the last column of the table. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
last_data_row

Index of the last row of the data (table body). :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
last_header_row

Index of the last row of the header. :rtype: int

Note

This attributes available after execution of the write_table() method.

Type:return
make_worksheet(sheet_name=None)

Make a worksheet to the current workbook.

Parameters:sheet_name (str) – Name of the worksheet to create. The name will be automatically generated (like "Sheet1") if the sheet_name is empty.
open(file_path)

Open an Excel workbook file.

Parameters:file_path (str) – Excel workbook file path to open.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_table()

Write a table to the stream.

write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.2.2. SQLite writer class

class pytablewriter.SqliteTableWriter[source]

Bases: pytablewriter.writer.binary._interface.AbstractBinaryTableWriter

A table writer class for SQLite database.

write_table()

Write a table to a SQLite database.

Raises:
Example:

SQLite

close()

Close the current stream.

dump(output, close_after_write=True)[source]

Write data to the SQLite database file.

Parameters:
  • output (file descriptor or filepath) –
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

open(file_path)[source]

Open a SQLite database file.

Parameters:file_path (str) – SQLite database file path to open.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_table()

Write a table to the stream.

write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.3. Application specific formats

5.1.3.1. Elasticsearch writer

class pytablewriter.ElasticsearchWriter[source]

Bases: pytablewriter.writer._table_writer.AbstractTableWriter

A table writer class for Elasticsearch.

Dependency Packages:
 
index_name

Alias attribute for table_name.

document_type

Specify document type for indices. Defaults to "table".

write_table()

Create an index and put documents for each row to Elasticsearch.

You need to pass an elasticsearch.Elasticsearch instance to stream before calling this method. table_name/index_name used as the creating index name, invalid characters in the name are replaced with underscore ('_'). Document data types for documents are automatically detected from the data.

Raises:ValueError – If the stream has not elasticsearch.Elasticsearch instance.
Example:Elasticsearch
close()

Close the current stream.

format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_table()

Write a table to the stream.

write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

5.1.4. Base writers

class pytablewriter.writer._table_writer.TableWriterInterface[source]

Bases: object

Interface class for writing a table.

format_name

Format name for the writer. :rtype: str

Type:return
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
write_table()[source]

Write a table to the stream.

write_table_iter()[source]

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

class pytablewriter.writer._table_writer.AbstractTableWriter[source]

Bases: pytablewriter.writer._interface.TableWriterInterface

An abstract base class of table writer classes.

stream

Stream to write tables. You can use arbitrary stream which supported write method such as sys.stdout, file stream, StringIO, and so forth. Defaults to sys.stdout.

Example:Configure Output Stream
is_write_header

Write headers of a table if the value is True.

is_padding

Padding for each item in the table if the value is True.

is_escape_html_tag

Escape HTML tags in cells in the table if the value is True.

iteration_length

The number of iterations to write a table. This value used in write_table_iter() method. (defaults to -1 which means number of iterations is indefinite)

write_callback

The value expected to a function. The function called when for each of the iteration of writing a table completed. (defaults to None) Example, callback function definition is as follows:

def callback_example(iter_count, iter_length):
    print("{:d}/{:d}".format(iter_count, iter_length))

Arguments that passed to the callback is:

  • first argument: current iteration number (start from 1)
  • second argument: a total number of iteration
close()[source]

Close the current stream.

format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')[source]

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)[source]

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)[source]

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)[source]

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)[source]

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)[source]

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_table()[source]

Write a table to the stream.

write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

class pytablewriter.writer.text._text_writer.TextTableWriter[source]

Bases: pytablewriter.writer._table_writer.AbstractTableWriter, pytablewriter.writer.text._interface.TextWriterInterface

A base class for table writer with text formats.

column_delimiter

A column delimiter of a table.

char_left_side_row

A character of a left side of a row.

char_right_side_row

A character of a right side of a row.

char_cross_point

A character of the crossing point of column delimiter and row delimiter.

char_opening_row

A character of the first line of a table.

char_header_row_separator

A character of a separator line of the header and the body of the table.

char_value_row_separator

A character of a row separator line of the table.

char_closing_row

A character of the last line of a table.

is_write_header_separator_row

Write a header separator line of the table if the value is True.

is_write_value_separator_row

Write row separator line(s) of the table if the value is True.

is_write_opening_row

Write an opening line of the table if the value is True.

is_write_closing_row

Write a closing line of the table if the value is True.

is_write_null_line_after_table

Write a blank line of after writing a table if the value is True.

table_char

Character attributes that compose a table

close()

Close the current stream.

dump(output, close_after_write=True)[source]

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()[source]

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()[source]

Write a null line to the stream.

write_table()[source]

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.

class pytablewriter.writer.text._text_writer.IndentationTextTableWriter[source]

Bases: pytablewriter.writer.text._text_writer.TextTableWriter, pytablewriter.writer.text._interface.IndentationInterface

A base class for table writer with indentation text formats.

indent_string

Indentation string for each level.

close()

Close the current stream.

dec_indent_level()[source]

Decrement the current indent level.

dump(output, close_after_write=True)

Write data to the output with tabular format.

Parameters:
  • output (file descriptor or str) – file descriptor or path to the output file.
  • close_after_write (bool, optional) – Close the output after write. Defaults to True.
dumps()

Get rendered tabular text from the table data.

Only available for text format table writers.

Returns:Rendered tabular text.
Return type:str
format_name

Format name for the writer. :rtype: str

Type:return
from_csv(csv_source, delimiter=', ')

Set tabular attributes to the writer from a character-separated values (CSV) data source. Following attributes are set to the writer by the method:

table_name also be set if the CSV data source is a file. In that case, table_name is as same as the filename.

Parameters:

csv_source (str) – Input CSV data source either can be designated CSV text or CSV file path.

Examples:

Using CSV as tabular data source

Dependency Packages:
 
from_dataframe(dataframe, add_index_column=False)

Set tabular attributes to the writer from pandas.DataFrame. Following attributes are set by the method:

Parameters:
  • dataframe (pandas.DataFrame or str) – Input pandas.DataFrame object or pickle.
  • add_index_column (bool, optional) – If True, add a column of index of the dataframe. Defaults to False.

Example

Using pandas DataFrame as tabular data source

from_series(series, add_index_column=True)

Set tabular attributes to the writer from pandas.Series. Following attributes are set by the method:

Parameters:
  • series (pandas.Series) – Input pandas.Series object.
  • add_index_column (bool, optional) – If True, add a column of index of the series. Defaults to True.
from_tabledata(value, is_overwrite_table_name=True)

Set tabular attributes to the writer from TableData. Following attributes are configured:

TableData can be created from various data formats by pytablereader. More detailed information can be found in https://pytablereader.rtfd.io/en/latest/

Parameters:value (tabledata.TableData) – Input table data.
from_tablib(tablib_dataset)

Set tabular attributes to the writer from tablib.Dataset.

header_list

alias for headers.

headers

List of table header to write.

inc_indent_level()[source]

Increment the current indent level.

set_indent_level(indent_level)[source]

Set the current indent level.

Parameters:indent_level (int) – New indent level.
set_style(column, style)

Set style for a specific column.

Parameters:
  • column (int or str) – Column specifier. column index or header name correlated with the column.
  • style (Style) – Style value to be set to the column.
Raises:

ValueError – If the column specifier is invalid.

style_list

alias for styles.

styles

Output Style for each column.

Returns:
Return type:list of Style
support_split_write
True if the writer supported iterative table writing (write_table_iter method).
Return type:bool
Type:return
table_name

Name of the table.

tabledata

Table data. :rtype: tabledata.TableData

Type:return
type_hint_list

alias for type_hints.

type_hints

Type hints for each column of the tabular data. Writers convert data for each column using the type hints information before writing tables when you call write_xxx methods.

Acceptable values are as follows:

  • None (automatically detect column type from values in the column)
  • pytablewriter.Bool
  • pytablewriter.DateTime
  • pytablewriter.Dictionary
  • pytablewriter.Infinity
  • pytablewriter.Integer
  • pytablewriter.List
  • pytablewriter.Nan
  • pytablewriter.NoneType
  • pytablewriter.NullString
  • pytablewriter.RealNumber
  • pytablewriter.String

If a type-hint value is not None, the writer tries to convert data for each data in a column to type-hint class. If the type-hint value is None or failed to convert data, the writer automatically detect column data type from the column data.

If type_hints is None, the writer detects data types for all of the columns automatically and writes a table by using detected column types.

Defaults to None.

Examples:
value_matrix

Tabular data to write.

write_null_line()

Write a null line to the stream.

write_table()

Write a table to the stream.

Note

  • None values are written as an empty string.
write_table_iter()

Write a table with iteration. “Iteration” means that divide the table writing into multiple processes. This method is useful, especially for large data. The following are premises to execute this method:

Call back function (Optional): Callback function is called when for each of the iteration of writing a table is completed. To set call back function, set a callback function to the write_callback attribute.

Raises:pytablewriter.NotSupportedError – If the class does not support this method.

Note

Following classes do not support this method: HtmlTableWriter, RstGridTableWriter, RstSimpleTableWriter. support_split_write attribute return True if the class is supporting this method.