Abstract Output Adapter

class AbstractOutputAdapter(output_ctx)[source]

Abstract class for output adapters. Adapters handles writing spreadsheets to external data source, e.g. Google Sheets.

Parameters:

output_ctx (OutputContext) – Output context. Contains empty dictionary, that can be used to store state, previous output path (if any) and state form previous run (if any). Adapter should update the state and output_path attributes. Both will be stored even if the adapter fails.

abstract finalize(task_ctx, exc=None)[source]

Closes the output file and performs any additional required tasks, such as uploading the output etc.

This method is always called at the end of the report, even in case of an exception. If an exception is raised, it is passed as an argument. Called only if initialize() was previously called.

Parameters:
abstract initialize(task_ctx)[source]

Initializes the output file. This method is called at the beginning of output, before any sheets are written.

Parameters:

task_ctx (TaskContextInterface) – Task context.

abstract write_output(task_ctx, sheets)[source]

Writes one or more sheets to the output.

Parameters:

Arguments Passed to Adapter

When invoked, the adapter will be passed instances of ppc_robot_lib.tasks.task_context.TaskContextInterface, ppc_robot_lib.output.types.OutputContext and ppc_robot_lib.output.types.SheetData.

class OutputContext(state, output_path, previous_state=None)[source]

Context that will be passed to output adapters. Contains current state of the output and state stored from previous runs (including original output_path for update).

Parameters:
  • state (dict[str, Any]) – Empty dicitionary with state. The adapter can use this dictionary to store state between runs. The dictionary is always empty and will be stored. On the next run, the dictionary will be passed in the previous_state parameter. Everything you store here must be JSON-serializable.

  • output_path (str | None) – Output path. Can be updated by the adapter, will be stored in the database.

  • previous_state (dict[str, Any]) – Read-only state from previous run. Will be None if this is the first run.

class SheetData(sheet_name, row_columns, merges, formats, data, header_row_count, sheet_id, freeze_header, freeze_columns, row_height=None, create_filter=False, currency_column_index=None, embedded_charts=None)[source]

Represents a sheet with data ready to be written to output.

Parameters:
  • sheet_name (str) – Sheet name.

  • row_columns (list[Column]) – Mapping of rows to columns.

  • merges (set[MergeDef]) – Definitions of cell merges in header.

  • formats (list[list[CellStyle]]) – Cell styles for the header.

  • data (SheetDataAdapter) – Complete data matrix, beginning with table header.

  • header_row_count (int) – Number of rows of the header.

  • sheet_id (int) – Sheet identifier.

  • freeze_header (bool) – Should the adapter freeze the header rows?

  • freeze_columns (int) – Number of columns to be freezed (will be used as row header).

  • row_height (int | None) – Row height. If not set, default of the given output platform will be used.

  • create_filter (bool) – Create a filterable table in the output sheet. If not given, no filtering will be applied and no user-changes will be discarded.

  • currency_column_index (int) – Index of a column that will contain currency code for individual rows.