csv#

Description#

A plugin for managing CSV files.

Configuration#

csv:
    # No configuration required

Actions#

Module reference#

class platypush.plugins.csv.CsvPlugin(**kwargs)[source]#

Bases: Plugin

A plugin for managing CSV files.

__init__(**kwargs)#
read(filename: str, delimiter: str = ',', quotechar: str | None = '"', start: int = 0, limit: int | None = None, reverse: bool = False, has_header: bool = None, column_names: List[str] | None = None, dialect: str = 'excel')[source]#

Gets the content of a CSV file.

Parameters:
  • filename – Path of the file.

  • delimiter – Field delimiter (default: ,).

  • quotechar – Quote character (default: ").

  • start – (Zero-based) index of the first line to be read (starting from the last if reverse is True) (default: 0).

  • limit – Maximum number of lines to be read (default: all).

  • reverse – If True then the lines will be read starting from the last (default: False).

  • has_header – Set to True if the first row of the file is a header, False if the first row isn’t expected to be a header (default: None, the method will scan the first chunk of the file and estimate whether the first line is a header).

  • column_names – Specify if the file has no header or you want to override the column names.

  • dialect – CSV dialect (default: excel).

static reversed_blocks(f: TextIO, blocksize=4096)[source]#

Generate blocks of file’s contents in reverse order.

write(filename: str, rows: List[List[Any] | Dict[str, Any]], truncate: bool = False, delimiter: str = ',', quotechar: str | None = '"', dialect: str = 'excel')[source]#

Writes lines to a CSV file.

Parameters:
  • filename – Path of the CSV file.

  • rows – Rows to write. It can be a list of lists or a key->value dictionary where the keys match the names of the columns. If the rows are dictionaries then a header with the column names will be written to the file if not available already, otherwise no header will be written.

  • truncate – If True then any previous file content will be removed, otherwise the new rows will be appended to the file (default: False).

  • delimiter – Field delimiter (default: ,).

  • quotechar – Quote character (default: ").

  • dialect – CSV dialect (default: excel).