gslides package

Submodules

gslides.chart module

Charts & series class

class gslides.chart.Chart(data: gslides.frame.Frame, x_axis_column: str, series: Sequence[gslides.chart.Series], stacking: Optional[bool] = None, title: Optional[str] = None, x_axis_label: Optional[str] = None, y_axis_label: Optional[str] = None, x_min: Optional[float] = None, x_max: Optional[float] = None, y_min: Optional[float] = None, y_max: Optional[float] = None, x_axis_format: Optional[str] = None, y_axis_format: Optional[str] = None, palette: Optional[str] = None, legend_position: Optional[str] = None)[source]

Bases: object

An object that configures the creation of a chart in Google sheets.

Parameters
  • data (gslides.Frame) – The data in Google sheets that will be plotted, a frame object

  • x_axis_column (str) – The name column that corresponds to the x-values. No parameter needed for a histogram.

  • series (list[gslides.addchart.series]) – The gslides.addchart.series objects to plot

  • stacking (str, optional) – The type of stacking to plot, see gslides.config.CHART_PARAMS[‘stacking’] for accepted parameters

  • title (str, optional) – The title for the plot

  • x_axis_label (str, optional) – The x_axis_label for the plot

  • y_axis_label (str, optional) – The y_axis_label for the plot

  • x_min (float, optional) – The minimum value for the x axis

  • x_max (float, optional) – The maximum value for the x axis

  • y_min (float, optional) – The minimum value for the y axis

  • y_max (float, optional) – The maximum value for the y axis

  • x_axis_format (str, optional) – The format of the x axis labels. Either the values https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#NumberFormatType or patterns here https://developers.google.com/sheets/api/guides/formats are accepted

  • y_axis_format (str, optional) – The format of the y axis labels. Either the values https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#NumberFormatType or patterns here https://developers.google.com/sheets/api/guides/formats are accepted

  • palette (str, optional) – The palette to use to plot, see gslides.colors.base_palettes for accepted parameters

  • legend_position (str, optional) – The position of the legend to plot, see gslides.config.CHART_PARAMS[‘stacking’] for accepted parameters

  • size (tuple, optional) – A tuple for the width and length of the plot in pixels. The Google suggested size is 600 by 371 pixels.

property chart_id: Optional[str]

Returns the chart_id of the created chart.

Raises

RuntimeError – Must run the execute method before passing the chart id

Returns

The chart_id of the created chart.

Return type

str

create(size: Tuple[int, int] = (600, 371)) dict[source]

Creates the chart in Googe sheets

Parameters

size (tuple) – Tuple of width and height in PX

Returns

The json returned by the call

Return type

dict

render_basic_chart_json(size: Tuple[int, int]) dict[source]

Renders the json for the creation of a basic chart. See here https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/charts#histogramchartspec for information about basic charts.

Parameters

size (tuple) – Tuple of width and height in PX

Returns

json for the API call

Return type

dict

render_histogram_chart_json(size: Tuple[int, int]) dict[source]

Renders the json for the creation of a basic chart. See here https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/charts#histogramchartspec for information about basic charts.

Parameters

size (tuple) – Tuple of width and height in PX

Returns

json for the API call

Return type

dict

class gslides.chart.Series(type: str, **kwargs: Dict[str, Any])[source]

Bases: object

Parent class for all series configurations.

Parameters
  • type (str) – Type of series

  • **kwargs (dict) – Dictionary of keyword arguments

classmethod area(series_columns: Optional[List[str]] = None, line_style: Optional[str] = None, line_width: Optional[int] = None, point_enabled: bool = False, point_shape: Optional[str] = None, point_size: Optional[int] = None, data_label_enabled: bool = False, data_label_placement: Optional[str] = None, color: Optional[str] = None) gslides.chart.TSeries[source]

A area plot

Parameters
  • series_columns (list, optional) – The columns to plot. None or an empty list will plot all columns

  • line_style (str, optional) – The style of line to plot, see gslides.config.CHART_PARAMS[‘line_style’] for accepted parameters

  • line_width (int, optional) – The width of line to plot

  • point_enabled (bool, optional) – Boolean for whether the plot should include points

  • point_shape (str, optional) – The shape of point to plot, see gslides.config.CHART_PARAMS[‘point_shape’] for accepted parameters

  • point_size (int, optional) – The size of point to plot

  • data_label_enabled (bool, optional) – Boolean for whether the plot should include data labels

  • data_label_placement (str, optional) – The placement of the data label to plot, see gslides.config.CHART_PARAMS[‘data_label_placement’] for accepted parameters

  • color (str, optional) – A color to override the existing palette. Parameters can either be a hex-code or a named colored. see gslides.config.color_mapping.keys() for accepted named colors

Returns

A Series object

Return type

Series

classmethod column(series_columns: Optional[List[str]] = None, data_label_enabled: bool = False, data_label_placement: Optional[str] = None, color: Optional[str] = None) gslides.chart.TSeries[source]

A column plot

Parameters
  • series_columns (list, optional) – The columns to plot. None or an empty list will plot all columns

  • data_label_enabled (bool, optional) – Boolean for whether the plot should include data labels

  • data_label_placement (str, optional) – The placement of the data label to plot, see gslides.config.CHART_PARAMS[‘data_label_placement’] for accepted parameters

  • color (str, optional) – A color to override the existing palette. Parameters can either be a hex-code or a named colored. see gslides.config.color_mapping.keys() for accepted named colors

Returns

A Series object

Return type

Series

classmethod histogram(series_columns: Optional[List[str]] = None, bucket_size: Optional[int] = None, outlier_percentage: Optional[float] = None, color: Optional[str] = None) gslides.chart.TSeries[source]

A histogram plot

Parameters
  • series_columns (list, optional) – The columns to plot. None or an empty list will plot all columns

  • bucket_size (int, optional) – The size of the bucket

  • outlier_percentage (float, optional) – The percentile at which oberservations should be excluded

  • color (str, optional) – A color to override the existing palette. Parameters can either be a hex-code or a named colored. see gslides.config.color_mapping.keys() for accepted named colors

Returns

A Series object

Return type

Series

classmethod line(series_columns: Optional[List[str]] = None, line_style: Optional[str] = None, line_width: Optional[int] = None, point_enabled: bool = False, point_shape: Optional[str] = None, point_size: Optional[int] = None, data_label_enabled: bool = False, data_label_placement: Optional[str] = None, color: Optional[str] = None) gslides.chart.TSeries[source]

A line plot

Parameters
  • series_columns (list, optional) – The columns to plot. None or an empty list will plot all columns

  • line_style (str, optional) – The style of line to plot, see gslides.config.CHART_PARAMS[‘line_style’] for accepted parameters

  • line_width (int, optional) – The width of line to plot

  • point_enabled (bool, optional) – Boolean for whether the plot should include points

  • point_shape (str, optional) – The shape of point to plot, see gslides.config.CHART_PARAMS[‘point_shape’] for accepted parameters

  • point_size (int, optional) – The size of point to plot

  • data_label_enabled (bool, optional) – Boolean for whether the plot should include data labels

  • data_label_placement (str, optional) – The placement of the data label to plot, see gslides.config.CHART_PARAMS[‘data_label_placement’] for accepted parameters

  • color (str, optional) – A color to override the existing palette. Parameters can either be a hex-code or a named colored. see gslides.config.color_mapping.keys() for accepted named colors

Returns

A Series object

Return type

Series

render_basic_chart_json(palette: Optional[gslides.colors.Palette], sheet_id: str, start_row_index: int, end_row_index: int, start_column_index: int, end_column_index: int, type: Optional[str] = None) dict[source]

Renders the json for the creation of a basic chart. See here https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/charts#BasicChartSpec for information about basic charts.

Parameters
  • palette (Palette) – Palette object to control colors

  • sheet_id (str) – ID for the Google sheet.

  • start_row_index (int) – The starting index of the row

  • end_row_index (int) – The ending index of the row

  • start_column_index (int) – The starting index of the column

  • end_column_index (int) – The ending index of the column

  • type (str, optional) – Type of series

Returns

json for the API call

Return type

dict

render_histogram_chart_json(palette: Optional[gslides.colors.Palette], sheet_id: str, start_row_index: int, end_row_index: int, start_column_index: int, end_column_index: int) dict[source]

Renders the json for the creation of a basic chart. See here https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/charts#histogramchartspec for information about basic charts.

Parameters
  • palette (Palette) – Palette object to control colors

  • sheet_id (str) – ID for the Google sheet.

  • start_row_index (int) – The starting index of the row

  • end_row_index (int) – The ending index of the row

  • start_column_index (int) – The starting index of the column

  • end_column_index (int) – The ending index of the column

Returns

json for the API call

Return type

dict

classmethod scatter(series_columns: Optional[List[str]] = None, point_shape: Optional[str] = None, point_size: Optional[int] = None, data_label_enabled: bool = False, data_label_placement: Optional[str] = None, color: Optional[str] = None) gslides.chart.TSeries[source]

A scatter plot

Parameters
  • series_columns (list, optional) – The columns to plot. None or an empty list will plot all columns

  • point_shape (str, optional) – The shape of point to plot, see gslides.config.CHART_PARAMS[‘point_shape’] for accepted parameters

  • point_size (int, optional) – The size of point to plot

  • data_label_enabled (bool, optional) – Boolean for whether the plot should include data labels

  • data_label_placement (str, optional) – The placement of the data label to plot, see gslides.config.CHART_PARAMS[‘data_label_placement’] for accepted parameters

  • color (str, optional) – A color to override the existing palette. Parameters can either be a hex-code or a named colored. see gslides.config.color_mapping.keys() for accepted named colors

Returns

A Series object

Return type

Series

gslides.colors module

Manages the color configuration

class gslides.colors.Palette(palette: Optional[str] = None)[source]

Bases: object

An iterator for a list of colors.

Parameters

palette (str) – Name of a palette

load_palette(name: str) None[source]

Loads a given palette

Parameters

palette (str) – Name of a palette

gslides.colors.translate_color(color: str) str[source]

Translates a color from a named color to a hex code

Parameters

color (str) – Named color

Returns

Hex code corresponding to the color

Return type

str

Raises

ValueError

gslides.config module

class gslides.config.Creds[source]

Bases: object

The credentials object to build the connections to the APIs

set_credentials(credentials: Optional[google.oauth2.credentials.Credentials]) None[source]

Sets the credentials

Parameters

credentials (google.oauth2.credentials.Credentials) – google.oauth2.credentials.Credentials

property sheet_service: googleapiclient.discovery.Resource

Returns the connects to the sheets API

Raises

RuntimeError – Must run set_credentials before executing method

Returns

API connection

Return type

googleapiclient.discovery.Resource

property slide_service: googleapiclient.discovery.Resource

Returns the connects to the slides API

Raises

RuntimeError – Must run set_credentials before executing method

Returns

API connection

Return type

googleapiclient.discovery.Resource

class gslides.config.Font[source]

Bases: object

The credentials object to build the connections to the APIs

set_font(font: str) None[source]

Sets the font

Parameters

font (str) – Font

class gslides.config.PackagePalette[source]

Bases: object

The credentials object to build the connections to the APIs

set_palette(palette: Optional[str]) None[source]

Sets the palette

Parameters

palette (str) – Palette

gslides.utils module

gslides.utils.black_or_white(rgb: Tuple[float, ...]) Tuple[float, ...][source]

Determines based on the luminosity of a color wether the text on top of that color should be black or white. See the following: https://en.wikipedia.org/wiki/Luminance_%28relative%29

Parameters

rgb (tuple) – The rgb values of the color

Returns

Black or white rgb

Return type

tuple

gslides.utils.cell_to_num(x: str) Tuple[int, int][source]

Converts a cell to a row, column index

Parameters

x (str) – Name of the cell (e.g. A2)

Returns

Row, column index

Return type

tuple

gslides.utils.char_to_num(x: str) int[source]

Converts a character to a number

Parameters

x (str) – Character

Returns

Corresponding number

Return type

int

gslides.utils.clean_dtypes(x: Any) Optional[Union[str, float, int, numpy.int64, numpy.float64]][source]

Cleans the datatypes of an obersevation to either int, float or string or None

Parameters

x (any) – Observation to clean

Returns

Clean observation

Return type

str, float, int, np.int64, np.float64, None

gslides.utils.clean_list_of_list(x: List[List]) List[List][source]

In a list of list with different length lists, appends None values to equalize the length of each list

Parameters

x (list) – List of lists

Returns

List of lists

Return type

list

gslides.utils.clean_nan(df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

Replaces NaN’s in a pandas dataframe

Parameters

df (pandas.DataFrame) – pandas.DataFrame

Returns

pandas.DataFrame

Return type

pandas.DataFrame

gslides.utils.determine_col_proportion(df: pandas.core.frame.DataFrame) numpy.ndarray[source]

Determines the percent size of a column based on the length of observiations

Parameters

df (pd.DataFrame) – Dataframe that will become a table

Returns

An array of proportions

Return type

np.ndarray

gslides.utils.emu_to_px(x: int) int[source]

Converts EMU to pixels

Parameters

x (int) – EMU

Returns

Pixels

Return type

int

gslides.utils.hex_to_rgb(x: str) Tuple[float, ...][source]

Converts a xexadecimal color code to r,g,b

Parameters

x (str) – Hexadecimal color code

Returns

R,G,B color code

Return type

Tuple

gslides.utils.json_chunk_extract(obj: Dict[str, Any], key: str, val: Union[str, int, float]) List[source]

Recursively fetch chunks from nested JSON based on a given key, value pair.

Parameters
  • obj (dict) – JSON to search

  • key (str) – Key that corresponds to the dictionary to chunk

  • val (str, int, float) – Val that corresponds to the dictionary to chunk

Returns

List of chunks

Return type

list

gslides.utils.json_chunk_key_extract(obj: Dict[str, Any], key: str) List[source]

Recursively fetch chunks from nested JSON based on a given key.

Parameters
  • obj (dict) – JSON to search

  • key (str) – Key that corresponds to the dictionary to chunk

Returns

List of chunks

Return type

list

gslides.utils.json_dict_extract(obj: Dict[str, Any], keys: Tuple) Dict[source]

Recursively fetch chunks from nested JSON based on a given key, value pair.

Parameters
  • obj (dict) – JSON to search

  • keys (tuple) – Tuple of multiple keys to search for in dictionary

Returns

Dictionary of values

Return type

dict

gslides.utils.json_val_extract(obj: Dict[str, Any], key: str) List[Any][source]

Recursively find values based on a given key

Parameters
  • obj (dict) – JSON to search

  • key (str) – Key that corresponds to the value to find

Returns

Value to return

Return type

any

gslides.utils.num_to_char(x: int) str[source]

Converts a number to a character

Parameters

x (int) – Number

Returns

Corresponding character

Return type

str

gslides.utils.optimize_size(y_scale: float, area: float = 222600) Tuple[float, float][source]

Optimizes the size of a chart so that it matches the suggested area (222600 pixels)

Parameters
  • y_scale (float) – Scale of the x axis to y axis

  • area (float, optional) – Description of parameter area.

Returns

x and y length combination

Return type

tuple

gslides.utils.validate_cell_name(x: str) str[source]

Validates that a cell name is valid

Parameters

x (str) – Cell name

Raises

ValueError – Invalid cell name.

Returns

Cell name

Return type

str

gslides.utils.validate_hex_color_code(x: str) str[source]

Short summary.

Parameters

x (str) – Hexadecimal color code

Raises

ValueError – Input a hexadecimal color code

Returns

Hexadecimal color code

Return type

str

gslides.utils.validate_params_float(params: dict) None[source]

Validates the parameters for the chart based on the float value

Parameters

params (dict) – Dictionary of parameters

Raises

ValueError

gslides.utils.validate_params_int(params: dict) None[source]

Validates the parameters for the chart based on the integer value

Parameters

params (dict) – Dictionary of parameters

Raises

ValueError

gslides.utils.validate_params_list(params: dict) None[source]

Validates the parameters for the chart based on a list

Parameters

params (dict) – Dictionary of parameters

Raises

ValueError

gslides.utils.validate_series_columns(params: dict) None[source]

Validates that the series column is None or a list

Parameters

params (dict) – Dictionary of parameters

Raises

ValueError

gslides.frame module

Frame class

class gslides.frame.CreateFrame(df: pandas.core.frame.DataFrame, spreadsheet_id: str, sheet_name: str, overwrite_data: bool = False, anchor_cell: str = 'A1')[source]

Bases: object

Class to create data in Google sheets.

Parameters
  • df (pandas.DataFrame) – Data to be created in Google sheets

  • spreadsheet_id (str) – The id associated with the spreadsheet

  • sheet_name (str) – The name associated with the sheet

  • start_row_index – The starting index of the row

  • overwrite_data (bool, optional) – Whether to overwrite the existing data

  • anchor_cell (str, optional) – The cell name (e.g. A5) that will correspond to the top left observation in the dataframe

execute() bool[source]

Executes the API call

Returns

Whether the function executed

Return type

bool

render_update_json() dict[source]

Renders the json to update the data in Google sheets

Returns

The json to do the update

Return type

dict

class gslides.frame.Frame(df: pandas.core.frame.DataFrame = Empty DataFrame Columns: [] Index: [], spreadsheet_id: str = '', sheet_id: int = 0, sheet_name: str = '', start_column_index: int = 0, start_row_index: int = 0, end_column_index: int = 0, end_row_index: int = 0, initialized: bool = False)[source]

Bases: object

An object that represents a table of data in Google sheets. Initialize the object through either the Frame.get or :class:`Frame.create class method.

Parameters
  • title (str, optional) – The title of the spreadsheet

  • sheet_name (str, optional) – The name of the sheet

  • df (pd.DataFrame, optional) – The dataframe

  • spreadsheet_id (str, optional) – The id of the spreadsheet

  • sheet_id (int, optional) – The id associated with the sheet

  • sheet_name – The name associated with the sheet

  • start_column_index (int) – The index of the starting column of the data

  • start_row_index (int) – The index of the starting row of the data

  • end_column_index (int) – The index of the ending column of the data

  • end_row_index (int) – The index of the ending row of the data

  • initialized (bool, optional) – A boolean whether the class has been initialized

classmethod create(df: pandas.core.frame.DataFrame, spreadsheet_id: str, sheet_id: int, sheet_name: str, overwrite_data: bool = False, anchor_cell: str = 'A1') gslides.frame.TFrame[source]

Creates the table of data in Google sheets

Parameters
  • df (pd.DataFrame) – The dataframe

  • spreadsheet_id (str) – The id of the spreadsheet

  • sheet_id (int) – The id associated with the sheet

  • sheet_name (str) – The name associated with the sheet

  • overwrite_data (bool, optional) – Whether to overwrite the existing data

  • anchor_cell (str) – The cell name (e.g. A5) that will correspond to the top left observation in the dataframe

Returns

gslides.Frame object

Return type

gslides.Frame

property data: gslides.frame.TFrame

Returns the Frame object of the data

:raises Must run the create or get method before passing the data :return: The Frame object :rtype: Frame

format_frame(column_mapping)[source]

Formats a column in Google sheets. See https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#NumberFormat for accepted number types; either a type value or pattern is accepted.

Parameters

column_mapping (dict) – A mapping of column name to number type

Example

>>> frame = Frame.get(...)
>>> frame.format_frame({'column1': '0.0%'})
classmethod get(spreadsheet_id: str, sheet_id: int, sheet_name: str, anchor_cell: str, bottom_right_cell: str) gslides.frame.TFrame[source]

Gets the table of data in Google sheets

Parameters
  • spreadsheet_id (str) – The id of the spreadsheet

  • sheet_id (int) – The id associated with the sheet

  • sheet_name (str) – The name associated with the sheet

  • anchor_cell (str) – The cell name (e.g. A5) that will correspond to the top left observation in the dataframe

  • bottom_right_cell (str) – The cell name (e.g. B7) that will correspond to the bottom right observation in the dataframe

Returns

gslides.Frame object

Return type

gslides.Frame

property get_method: str

Returns the corresponding get initialization method.

Returns

Get initialization method

Return type

str

render_format_frame(column_mapping: Dict[str, str])[source]

Renders the json to format a column in Google slides

Parameters

column_mapping (dict) – A mapping of column name to number type

Returns

JSON for the api call

Return type

dict

class gslides.frame.GetFrame(spreadsheet_id: str, sheet_id: int, sheet_name: str, anchor_cell: str, bottom_right_cell: str)[source]

Bases: object

Class to get data from Google sheets.

Parameters
  • spreadsheet_id (str) – The id associated with the spreadsheet

  • sheet_name (str) – The name associated with the sheet

  • anchor_cell (str) – The cell name (e.g. A5) that will correspond to the top left observation in the dataframe

  • bottom_right_cell (str) – The cell name (e.g. B10) that will correspond to the bottom right observation in the dataframe

execute() bool[source]

Executes the API call

Returns

Whether the function executed

Return type

bool

gslides.frame.format_type(number_type: str) Dict[str, Any][source]

Takes a specified number type and outputs the necessary json, controlling for the custom types. See the documentation here https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#NumberFormat for more information the formatting available. Either a type or pattern can be passed.

Parameters

number_type (str) – A string specifying the format of the cell

Returns

A dictionary providing the configuration

Return type

dict

gslides.frame.get_sheet_data(spreadsheet_id, sheet_name: str, start_column_index: int, start_row_index: int, end_column_index: int, end_row_index: int) List[List][source]

Gets the data from a given groups of cells in a sheet

Parameters
  • spreadsheet_id (str) – The id of the spreadsheet

  • sheet_name (str) – Sheet name to get data from

  • start_column_index (int) – The index of the starting column of the data

  • start_row_index (int) – The index of the starting row of the data

  • end_column_index (int) – The index of the ending column of the data

  • end_row_index (int) – The index of the ending row of the data

Returns

A list of lists capturing the data

Return type

list

gslides.presentation module

Creates the slides and charts in Google slides

class gslides.presentation.AddSlide(presentation_id: str, objects: List[Union[gslides.chart.Chart, gslides.table.Table]], layout: Tuple[int, int], insertion_index: Optional[int] = None, top_margin: int = 1017724, bottom_margin: int = 420575, left_margin: int = 0, right_margin: int = 0, page_size: Tuple[int, int] = (9144000, 5143500), title: str = 'Title placeholder', notes: str = 'Notes placeholder')[source]

Bases: object

The class that adds a slide to the presentation.

Parameters
  • presentation_id (str) – The presentation_id of the created presentation

  • objects (list) – List of Chart or Table objects

  • layout (tuple) – The layout of the chart objects in # of rows by # of columns

  • insertion_index (int, optional) – The slide index to insert new slide to. The lack of a parameter will insert the slide to the end of the presentation

  • top_margin (int, optional) – The top margin of the presentation in EMU

  • bottom_margin (int, optional) – The bottom margin of the presentation in EMU

  • left_margin (int, optional) – The left margin of the presentation in EMU

  • right_margin (int, optional) – The right margin of the presentation in EMU

  • page_size (tuple) – Tuple of the width and height of the presentation in EMU

  • title (str, optional) – The text for the title textbox

  • notes (str, optional) – The text for the notes textbox

execute() Tuple[str, Dict[Any, Any]][source]

Executes the sheets & slides API call.

execute_sheet() None[source]

Executes the sheets API call.

execute_slide() None[source]

Executes the slides API call.

render_json_copy_chart(chart: gslides.chart.Chart, size: Tuple[float, float], translate_x: float, translate_y: float) dict[source]

Renders the json to copy the charts in Google slides.

Parameters
  • chart (Chart) – The chart to copy

  • size (tuple) – Tuple of width and height in EMU

  • translate_x (float) – The number of EMU to translate the object by

  • translate_y (float) – The number of EMU to translate the object by

Returns

The json to do the update

Return type

dict

render_json_create_slide() dict[source]

Renders the json to create the slide in Google slides.

Returns

The json to do the update

Return type

dict

render_json_create_textboxes(slide_id: str) dict[source]

Renders the json to create the textboxes in Google slides.

Parameters

slide_id (str) – The slide_id of the slide to create textbox in

Returns

The json to do the update

Return type

dict

render_json_format_textboxes(title_box_id: int, notes_box_id: int) dict[source]

Renders the json to format the textboxes in Google slides.

Parameters
  • title_box_id (int) – The id of the title box

  • notes_box_id (int) – The id of the notes box

Returns

The json to do the update

Return type

dict

class gslides.presentation.Layout(x_length: float, y_length: float, layout: Tuple[int, int], x_border: float = 0.05, y_border: float = 0.01, spacing: float = 0.02)[source]

Bases: object

A class that manages the layout of objects on a canvas

Parameters
  • x_length (float) – The width of the canvase

  • y_length (float) – The height of the canvase

  • layout (tuple) – The grid layout of objects on the canvase (rows x columns)

  • x_border (float) – The % margin for the x border

  • y_border (float) – The % margin for the y border

  • spacing (float) – The % spacing between objects

property coord: Tuple[int, int]

Calculates the row and column of the given index.

Returns

Row index and column index

Return type

tuple

class gslides.presentation.Presentation(name: str = '', pr_id: str = '', sl_ids: list = [], ch_ids: dict = {}, page_size: Tuple[int, int] = (9144000, 5143500), initialized: bool = False)[source]

Bases: object

An object that represents a presentation in Google slides. Initialize the object through either the Presentation.get or Presentation.create class method.

Parameters
  • name (str) – Name of the presentation

  • pr_id (str) – The id of the presentation

  • sl_ids (list) – A list of the slide ids

  • ch_ids (dict) – A dictionary of the charts objects id’s and their corresponding title

  • page_size (tuple) – Tuple of the width and height of the presentation in EMU

  • initialized (bool) – Whether to object has been initialized

add_slide(objects: List[Union[gslides.chart.Chart, gslides.table.Table]], layout: Tuple[int, int], insertion_index: Optional[int] = None, top_margin: int = 1017724, bottom_margin: int = 420575, left_margin: int = 0, right_margin: int = 0, title: str = 'Title placeholder', notes: str = 'Notes placeholder') None[source]

Add a slide to the presentation.

Parameters
  • objects (list) – List of Chart or Table objects

  • layout (tuple) – The layout of the chart objects in # of rows by # of columns

  • insertion_index (int, optional) – The slide index to insert new slide to. The lack of a parameter will insert the slide to the end of the presentation

  • top_margin (int, optional) – The top margin of the presentation in EMU

  • bottom_margin (int, optional) – The bottom margin of the presentation in EMU

  • left_margin (int, optional) – The left margin of the presentation in EMU

  • right_margin (int, optional) – The right margin of the presentation in EMU

  • title (str, optional) – The text for the title textbox

  • notes (str, optional) – The text for the notes textbox

property chart_ids: dict

Returns the chart_ids of the created presentation.

Raises

RuntimeError – Must run the create or get method before passing the slides ids

Returns

The chart ids of the created presentation

Return type

dict

classmethod create(name: str = 'Untitled') gslides.presentation.TPresentation[source]

Class method that creates a new presentation. To note, due to an issue in the API page size is currently not supported.

Parameters

name (str) – Name of the presentation

Returns

A presentation object

Return type

Presentation

download_slide(slide_id: str, path: str, image_size: str = 'LARGE') None[source]

Downloads a given slide to a file in png format

Parameters
  • slide_id (str) – The id of the slide to show

  • path (str) – Path to write png file to

  • image_size (str) – String to configure the image size

classmethod get(presentation_id: str) gslides.presentation.TPresentation[source]

Class method that gets a presentation.

Parameters

presentation_id (str) – Id of the presentation

Returns

A presentation object

Return type

Presentation

property get_method: str

Returns the corresponding get initialization method.

Returns

Get intialization method

Return type

str

property presentation_id: str

Returns the presentation_id of the created presentation.

Raises

RuntimeError – Must run the create or get method before passing the presentation id

Returns

The presentation_id of the created presentation

Return type

str

rm_slide(slide_id: str) None[source]

Removes a slide based on a slide id.

Parameters

slide_id (str) – The slide_id of the slide to delete

show_slide(slide_id: str, image_size: str = 'LARGE') IPython.core.display.Image[source]

Displays a given slide in a Jupyter notebook.

Parameters
  • slide_id (str) – The id of the slide to show

  • image_size (str) – String to configure the image size

Returns

ipython Image object

Return type

Image

property slide_ids: List[str]

Returns the slide_ids of the created presentation.

Raises

RuntimeError – Must run the create or get method before passing the slides ids

Returns

The slide ids of the created presentation

Return type

str

template(mapping: dict, slide_ids: list = []) None[source]

Replaces all text encaspulated with {{ <TEXT> }} with input.

Parameters
  • mapping (dict) – Dictionary mapping old text to new text

  • slide_ids (list, optional) – The slides to apply template on. If none, then all slides will be considered.

update_charts() None[source]

Updates all the charts in the slides deck with refreshed underlying data.

gslides.table module

Creates the table in Google slides

class gslides.table.Table(data: Union[gslides.frame.Frame, pandas.core.frame.DataFrame], font_size: int = 12, header: bool = True, stub: bool = False, header_background_color: str = 'black', stub_background_color: str = 'black', column_proportions: Optional[List[float]] = None)[source]

Bases: object

The class that creates a table.

Parameters
  • data (Frame or pd.DataFrame) – Data to insert into the table

  • font_size (int) – Font size in the unit PT

  • header (bool) – Whether to enable formatting on the header row

  • stub (bool) – Whether to enable formatting on the stub (1st) column

  • header_background_color (str) – A color to set the header background. Parameters can either be a hex-code or a named color. See gslides.config.color_mapping.keys() for accepted named colors

  • stub_background_color (str) – A color to set the stub background. Parameters can either be a hex-code or a named color. See gslides.config.color_mapping.keys() for accepted named colors

  • column_proportions (list of floats) – A list of floats representing the proportion of each column

create(presentation_id: str, slide_id: str, size: Tuple[float, float] = (3000000, 3000000), translate_x: float = 0, translate_y: float = 0) None[source]

Creates the table in Google slides

Parameters
  • presentation_id (str) – The presentation_id of the presentation to create to create table in

  • slide_id (str) – The slide_id of the slide to create table in

  • size (tuple) – Tuple of width and height in EMU

  • translate_x (float) – The number of EMU to translate the object by

  • translate_y (float) – The number of EMU to translate the object by

render_create_table_json(sl_id: str) Dict[str, Any][source]

Renders the create table json

Parameters

sl_id (str) – Slide id

Returns

json for the API call

Return type

dict

render_update_table_json(tbl_id: str, size: Tuple[float, float], translate_x: float, translate_y: float) dict[source]

Renders the json for the update of table properties.

Parameters
  • tbl_id (str) – Table id

  • size (tuple) – Tuple of width and height in EMU

  • translate_x (float) – The number of EMU to translate the object by

  • translate_y (float) – The number of EMU to translate the object by

Returns

json for the API call

Return type

dict

Module contents

Top-level package for gslides.

gslides.initialize_credentials(credentials: Optional[google.oauth2.credentials.Credentials]) None[source]

Intializes credentials for all classes in the package.

Parameters

credentials (google.oauth2.credentialsCredentials) – Credentials to build api connection

gslides.set_font(font: str) None[source]

Sets the font for all objects

Parameters

font (str) – Font

gslides.set_palette(palette: str) None[source]

Sets the palette for all charts

Parameters

palette (str) – The palette to use