Python API

Google

class RPA.Cloud.Google.Google(robocloud_vault_name: str = None, robocloud_vault_secret_key: str = None)

Bases: RPA.Cloud.Google.ServiceVision, RPA.Cloud.Google.ServiceNaturalLanguage, RPA.Cloud.Google.ServiceVideoIntelligence, RPA.Cloud.Google.ServiceTranslation, RPA.Cloud.Google.ServiceTextToSpeech, RPA.Cloud.Google.ServiceSpeechToText, RPA.Cloud.Google.ServiceStorage, RPA.Cloud.Google.ServiceSheets, RPA.Cloud.Google.ServiceAppsScript, RPA.Cloud.Google.ServiceDrive

Google is a library for operating with Google API endpoints.

Usage requires the following steps:

  • Create a GCP project

  • Create a service account key file (JSON) and save it to a place the robot can use it

  • Enable APIs

  • Install rpaframework[google]

Google authentication

Authentication for Google is set with service credentials JSON file which can be given to the library in three different ways or with credentials.json, which is used for OAuth authentication.

Methods when using service credentials:

  • Method 1 as environment variables, GOOGLE_APPLICATION_CREDENTIALS with path to JSON file.

  • Method 2 as keyword parameter to Init Storage Client for example.

  • Method 3 as Robocloud vault secret. The vault name and secret key name needs to be given in library init or with keyword Set Robocloud Vault. Secret value should contain JSON file contents.

Method 1. service credentials using environment variable

*** Settings ***
Library   RPA.Cloud.Google

*** Tasks ***
Init Google services
    # NO parameters for Vision Client, expecting to get JSON
    # with GOOGLE_APPLICATION_CREDENTIALS environment variable
    Init Vision Client

Method 2. service credentials with keyword parameter

*** Settings ***
Library   RPA.Cloud.Google

*** Tasks ***
Init Google services
    Init Speech To Text Client  /path/to/service_credentials.json

Method 3. setting Robocloud Vault in the library init

*** Settings ***
Library   RPA.Cloud.Google
...       robocloud_vault_name=googlecloud
...       robocloud_vault_secret_key=servicecreds

*** Tasks ***
Init Google services
    Init Storage Client   use_robocloud_vault=${TRUE}

Method 3. setting Robocloud Vault with keyword

*** Settings ***
Library   RPA.Cloud.Google

*** Tasks ***
Init Google services
    Set Robocloud Vault   vault_name=googlecloud  vault_secret_key=servicecreds
    Init Storage Client   use_robocloud_vault=${TRUE}

Method when using OAuth credentials.json:

The Google Apps Script and Google Drive services are authenticated using this method.

*** Settings ***
Library   RPA.Cloud.Google

*** Variables ***
@{SCRIPT_SCOPES}     forms   spreadsheets

*** Tasks ***
Init Google OAuth services
    Init Apps Script Client   /path/to/credentials.json   ${SCRIPT_SCOPES}

Creating and using OAuth token file

The token file can be created using credentials.json by running command:

rpa-google-oauth --service drive or rpa-google-oauth --scopes drive.appdata,drive.file,drive.install

This will start web based authentication process, which outputs the token at the end. Token could be stored into Robocorp Vault where it needs to be in variable google-oauth.

Example Vault content.

"googlecloud": {
    "oauth-token": "gANfd123321aabeedYsc"
}

Using the Vault.

*** Keywords ***
Set up Google Drive authentication
    Set Robocloud Vault    vault_name=googlecloud
    Init Drive Client    use_robocloud_vault=True

Requirements

Due to number of dependencies related to Google Cloud services this library has been set as an optional package for rpaframework.

This can be installed by opting in to the google dependency:

pip install rpaframework[google]

Examples

Robot Framework

*** Settings ***
Library   RPA.Cloud.Google

*** Variables ***
${SERVICE CREDENTIALS}    ${/}path${/}to${/}service_credentials.json
${BUCKET_NAME}            testbucket12213123123

*** Tasks ***
Upload a file into a new storage bucket
    [Setup]   Init Storage Client   ${SERVICE CREDENTIALS}
    Create Bucket    ${BUCKET_NAME}
    Upload File      ${BUCKET_NAME}   ${/}path${/}to${/}file.pdf  myfile.pdf
    @{files}         List Files   ${BUCKET_NAME}
    FOR   ${file}  IN   @{files}
        Log  ${file}
    END

Python

from RPA.Cloud.Google import Google

library = Google
service_credentials = '/path/to/service_credentials.json'

library.init_vision_client(service_credentials)
library.init_text_to_speech(service_credentials)

response = library.detect_text('imagefile.png', 'result.json')
library.synthesize_speech('I want this said aloud', target_file='said.mp3')
ROBOT_LIBRARY_DOC_FORMAT = 'REST'
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
analyze_sentiment(text_file: str, file_type: str = 'text', json_file: str = None, lang=None) → dict

Analyze sentiment in a text file

Parameters
  • text_file – source text file

  • json_file – json target to save result, defaults to None

  • lang – language code of the source, defaults to None

Returns

analysis response

annotate_image(image_uri: str, json_file: str = None) → dict

Annotate image

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

annotate_video(video_uri: str = None, video_file: str = None, json_file: str = None, features: list = None)

Annotate video

Possible values for features:

  • FEATURE_UNSPECIFIED, Unspecified.

  • LABEL_DETECTION, Label detection. Detect objects, such as dog or flower.

  • SHOT_CHANGE_DETECTION, Shot change detection.

  • EXPLICIT_CONTENT_DETECTION, Explicit content detection.

  • SPEECH_TRANSCRIPTION, Speech transcription.

  • TEXT_DETECTION, OCR text detection and tracking.

  • OBJECT_TRACKING, Object detection and tracking.

  • LOGO_RECOGNITION, Logo detection, tracking, and recognition.

If video_uri is given then that is used even if video_file is None.

Parameters
  • video_uri – Google Cloud Storage URI

  • video_file – filepath to video

  • json_file – json target to save result, defaults to None

  • features – list of annotation features to detect, defaults to [“LABEL_DETECTION”, “SHOT_CHANGE_DETECTION”]

Returns

annotate result

classify_text(text_file, json_file, lang=None)

Classify text

Parameters
  • text_file – source text file

  • json_file – json target to save result, defaults to None

  • lang – language code of the source, defaults to None

Returns

classify response

clear_values(sheet_id: str, sheet_range: str) → None

Clear cell values for range of cells within a sheet

Parameters
  • sheet_id – target sheet

  • sheet_range – target sheet range

clients: dict = {}
create_bucket(bucket_name: str)

Create Google Cloud Storage bucket

Parameters

bucket_name – name as string

Returns

bucket

create_sheet(title: str) → str

Create empty sheet with a title

Parameters

title – name as string

Returns

created sheet_id

delete_bucket(bucket_name: str)

Delete Google Cloud Storage bucket

Bucket needs to be empty before it can be deleted.

Parameters

bucket_name – name as string

delete_files(bucket_name: str, files: Any)

Delete files in the bucket

Files need to be object name in the bucket.

Parameters
  • bucket_name – name as string

  • files – single file, list of files or comma separated list of files

Returns

list of files which could not be deleted, or True if all were deleted

detect_document(image_file: str, json_file: str = None) → dict

Detect document

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

detect_labels(image_file: str, json_file: str = None) → dict

Detect labels in the image

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

detect_text(image_file: str, json_file: str = None) → dict

Detect text in the image

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

download_files(bucket_name: str, files: Any)

Download files from a bucket

Example files: files = {“mytestimg”: “image1.png”, “mydoc”: “google.pdf

Parameters
  • bucket_name – name as string

  • files – list of object names or dictionary of object names and target files

Returns

list of files which could not be downloaded, or True if all were downloaded

drive_create_directory(folder: str = None)

Create new directory to Google Drive

Parameters

folder – name for the new directory

Raises

GoogleDriveError – if folder name is not given

Returns

created file id

drive_delete_file(file_id: str = None, file_dict: dict = None, query: str = None, multiple_ok: bool = False)

Delete file specified by id, file dictionary or query string

Note. Be extra careful when calling this keyword!

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target file, needs to match 1 file unless parameter multiple_ok is set to True

  • multiple_ok – set to True if it is ok to perform delete on more than 1 file

Returns

how many files where deleted

Example:

${folder_id}=  Drive Get Folder Id   datafolder
${deleted}=    Drive Delete File   query=name contains '.json' and '${folder_id}' in parents
...            multiple_ok=True
drive_download_files(file_dict: dict = None, query: str = None, limit: int = None, timeout: float = None)

Download files specified by file dictionary or query string

Parameters start, limit and timeout are used only when downloading files defined by query parameter.

Parameters
  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target files, defaults to None

  • start – start index from which to start download files

  • limit – maximum amount of files that are downloaded, defaults to None

  • timeout – maximum allowed time in seconds for download process

Returns

list of downloaded files

Example:

${files}=    Drive Search Files    query=name contains '.json'
FOR    ${f}    IN    @{files}
    Run Keyword If  ${f}[size] < 2000  Drive Download Files  file_dict=${f}
END

${folder_id}=   Drive Get Folder Id   datafolder
Drive Download Files  query=name contains '.json' and '${folder_id}' in parents  recurse=True
drive_export_file(file_id: str = None, file_dict: dict = None, target_file: str = None, mimetype: str = 'application/pdf')

Export Google Drive file using Drive export links

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • target_file – name for the exported file

  • mimetype – export mimetype, defaults to “application/pdf”

Example:

${files}=  Drive Search Files  query=name contains 'my example worksheet'
Drive Export File  file_dict=${files}[0]
drive_get_folder_id(folder: str = None)

Get file id for the folder

Parameters

folder – name of the folder to identify, by default returns drive’s root folder id

Returns

file id of the folder

Example:

${root_id}=    Drive Get Folder Id   # returns Drive root folder id
${folder_id}=  Drive Get Folder Id  subdir
drive_move_file(file_id: str = None, file_dict: dict = None, query: str = None, folder: str = None, folder_id: str = None, multiple_ok: bool = False)

Move file specified by id, file dictionary or query string into target folder

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target file, needs to match 1 file

  • folder – name of the folder to move file into, is by default drive’s root folder id

  • folder_id – id of the folder to move file into, if set the folder parameter is ignored

  • multiple_ok – if True then moving more than 1 file

Returns

list of file ids

Raises

GoogleDriveError – if there are no files to move or target folder can’t be found

Example:

${source_id}=  Drive Get Folder Id  sourcefolder
${query}=      Set Variable  name contains '.json' and '${sourceid}' in parents
${files}=      Drive Move File  query=${query}  folder=target_folder  multiple_ok=True
drive_search_files(query: str = None, recurse: bool = False, folder_name: str = None) → list

Search Google Drive for files matching query string

Parameters
  • query – search string, defaults to None which means that all files and folders are returned

  • recurse – set to True if search should recursive

  • folder_name – search files in this directory

Raises

GoogleDriveError – if there is a request error

Returns

list of files

Example:

${files}=  Drive Search Files   query=name contains 'hello'
${files}=  Drive Search Files   query=modifiedTime > '2020-06-04T12:00:00'
${files}=  Drive Search Files   query=mimeType contains 'image/' or mimeType contains 'video/'
${files}=  Drive Search Files   query=name contains '.yaml'  recurse=True
${files}=  Drive Search Files   query=name contains '.yaml'  folder_name=datadirectory
drive_update_file(file_id: str = None, file_dict: dict = None, query: str = None, action: RPA.Cloud.Google.Update = <Update.star: 3>, multiple_ok: bool = False)

Update file specified by id, file dictionary or query string

Possible actions: - star - unstar - trash - untrash

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target file, needs to match 1 file

  • action – update action, default star file

  • multiple_ok – set to True if it is ok to perform update on more than 1 file

Returns

number of updated files

Example:

${folder_id}=  Drive Get Folder Id   datafolder
${updated}=    Drive Update File   query=name contains '.json' and '${folder_id}' in parents
...            action=star
...            multiple_ok=True
drive_upload_file(filename: str = None, folder: str = None, overwrite: bool = False, make_dir: bool = False) → dict

Upload files into Drive

Parameters
  • filename – name of the file to upload

  • folder – target folder for upload

  • overwrite – set to True if already existing file should be overwritten

  • make_dir – set to True if folder should be created if it does not exist

Raises

GoogleDriveError – if target_folder does not exist or trying to upload directory

Returns

uploaded file id

Example:

${file1_id}=  Drive Upload File   data.json  # Upload file to drive root
${file2_id}=  Drive Upload File   newdata.json  new_folder  make_dir=True
${file3_id}=  Drive Upload File   data.json  overwrite=True
face_detection(image_uri: str, json_file: str = None) → dict

Detect faces

Parameters
  • image_uri – Google Cloud Storage URI

  • json_file – json target to save result, defaults to None

Returns

detection response

get_bucket(bucket_name: str)

Get Google Cloud Storage bucket

Parameters

bucket_name – name as string

Returns

bucket

get_values(sheet_id: str, sheet_range: str, value_render_option: str = 'UNFORMATTED_VALUE', datetime_render_option: str = 'FORMATTED_STRING') → list

Get values from the range in the sheet

Parameters
  • sheet_id – target sheet

  • sheet_range – target sheet range

  • value_render_option – how values should be represented in the output defaults to “UNFORMATTED_VALUE”

  • datetime_render_option – how dates, times, and durations should be represented in the output, defaults to “FORMATTED_STRING”

global_scopes: list = []
init_apps_script_client(credentials_file: str = 'credentials.json', token_file: str = 'oauth.token', use_robocloud_vault: bool = False, scopes: list = None, save_token: bool = False) → None

Initialize Google Apps Script client

Parameters
  • credentials_file – filepath to credentials JSON

  • token_file – filepath to OAuth token file

  • use_robocloud_vault – if True the token is read from Robocloud

  • scopes – authenticated scopes, for example. [‘forms’, ‘spreadsheets’]

  • save_token – set to True if token should be saved to local file

init_drive_client(credentials_file: str = 'credentials.json', token_file: str = 'oauth.token', use_robocloud_vault: bool = False, scopes: list = None, save_token: bool = False) → None

Initialize Google Drive client

Parameters
  • credentials_file – filepath to credentials JSON

  • token_file – filepath to OAuth token file

  • use_robocloud_vault – if True the token is read from Robocloud

  • scopes – authenticated scopes, for example. [‘forms’, ‘spreadsheets’]

  • save_token – set to True if token should be saved to local file

init_natural_language_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Natural Language client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

init_sheets_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Sheets client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

init_speech_to_text_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Speech to Text client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

init_storage_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Storage client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

init_text_to_speech_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Text to Speech client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

init_translation_client(service_credentials_file: str = None, project_identifier: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Translation client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • project_identifier – identifier for Translation project

  • use_robocloud_vault – use json stored into Robocloud Vault

init_video_intelligence_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Video Intelligence client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

init_vision_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Vision client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

insert_values(sheet_id: str, sheet_range: str, values: list, major_dimension: str = 'COLUMNS', value_input_option: str = 'USER_ENTERED') → None

Insert values into sheet cells

Parameters
  • sheet_id – target sheet

  • sheet_range – target sheet range

  • values – list of values to insert into sheet

  • major_dimension – major dimension of the values, default COLUMNS

  • value_input_option – controls whether input strings are parsed or not, default USER_ENTERED

list_buckets() → list

List Google Cloud Storage buckets

Returns

list of buckets

list_files(bucket_name: str)

List files in the bucket

Parameters

bucket_name – name as string

Returns

list of object names in the bucket

list_supported_voices(language_code: str = None)

List supported voices for the speech

Parameters

language_code – voice languages to list, defaults to None (all)

Returns

list of supported voices

logger = None
recognize(audio_file_uri, encoding: str = 'FLAC', language_code: str = 'en_US', audio_channel_count=2)

Recognize text in the audio file

Parameters

audio_file_uri – Google Cloud Storage URI

Returns

recognized texts

region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
run_script(script_id: str, function_name: str, parameters: dict) → None

Run the Google Apps Script

Parameters
  • script_id – Google Script identifier

  • function_name – name of the script function

  • parameters – script function parameters as a dictionary

Raises

AssertionError – thrown when Google Script returns errors

Example:

&{params}=    Create Dictionary  formid=aaad4232  formvalues=1,2,3
${response}=  Run Script    abc21397283712da  submit_form   ${params}
Log Many   ${response}
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

synthesize_speech(text, language='en-US', name='en-US-Standard-B', gender='MALE', encoding='MP3', target_file='synthesized.mp3')

Synthesize speech synchronously

Parameters
  • text – input text to synthesize

  • language – voice language, defaults to “en-US”

  • name – voice name, defaults to “en-US-Standard-B”

  • gender – voice gender, defaults to “MALE”

  • encoding – result encoding type, defaults to “MP3”

  • target_file – save synthesized output to file, defaults to “synthesized.mp3”

Returns

synthesized output in bytes

translate(text: Any, source_language: str = None, target_language: str = None) → dict

Translate text

Parameters
  • text – text to translate

  • source_language – language code, defaults to None

  • target_language – language code, defaults to None

Returns

translated text

upload_file(bucket_name: str, filename: str, target_name: str)

Upload a file into a bucket

Parameters
  • bucket_name – name as string

  • filename – filepath to upload file

  • target_name – target object name

upload_files(bucket_name: str, files: dict)

Upload files into a bucket

Example files: files = {“mytestimg”: “image1.png”, “mydoc”: “google.pdf”}

Parameters
  • bucket_name – name as string

  • files – dictionary of object names and filepaths

class RPA.Cloud.Google.GoogleBase

Bases: object

Google base class for generic methods

clients: dict = {}
global_scopes: list = []
logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

exception RPA.Cloud.Google.GoogleDriveError

Bases: Exception

Raised with errors in Drive API

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception RPA.Cloud.Google.GoogleOAuthAuthenticationError

Bases: Exception

Raised when unable to get Google OAuth credentials.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class RPA.Cloud.Google.ServiceAppsScript

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Apps Script API

Note: The Apps Script API does not work with _service accounts_

Following steps are needed to authenticate and use the service:

  1. enable Apps Script API in the Cloud Platform project (GCP)

  2. create OAuth credentials so API can be authorized (download credentials.json which is needed to initialize service)

  3. the Google Script needs to be linked to Cloud Platform project number

  4. Google Script needs to have necessary OAuth scopes to access app which is being scripted

  5. necessary authentication scopes and credentials.json are needed to initialize service and run scripts

For more information about Google Apps Script API link_.

clients: dict = {}
global_scopes: list = []
init_apps_script_client(credentials_file: str = 'credentials.json', token_file: str = 'oauth.token', use_robocloud_vault: bool = False, scopes: list = None, save_token: bool = False) → None

Initialize Google Apps Script client

Parameters
  • credentials_file – filepath to credentials JSON

  • token_file – filepath to OAuth token file

  • use_robocloud_vault – if True the token is read from Robocloud

  • scopes – authenticated scopes, for example. [‘forms’, ‘spreadsheets’]

  • save_token – set to True if token should be saved to local file

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
run_script(script_id: str, function_name: str, parameters: dict) → None

Run the Google Apps Script

Parameters
  • script_id – Google Script identifier

  • function_name – name of the script function

  • parameters – script function parameters as a dictionary

Raises

AssertionError – thrown when Google Script returns errors

Example:

&{params}=    Create Dictionary  formid=aaad4232  formvalues=1,2,3
${response}=  Run Script    abc21397283712da  submit_form   ${params}
Log Many   ${response}
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.ServiceDrive

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Drive API

Note: The Drive API does not work with _service accounts_

Following steps are needed to authenticate and use the service:

  1. enable Drive API in the Cloud Platform project (GCP)

  2. create OAuth credentials so API can be authorized (download credentials.json which is needed to initialize service)

  3. necessary authentication scopes and credentials.json are needed to initialize service

For more information about Google Drive API link_.

clients: dict = {}
drive_create_directory(folder: str = None)

Create new directory to Google Drive

Parameters

folder – name for the new directory

Raises

GoogleDriveError – if folder name is not given

Returns

created file id

drive_delete_file(file_id: str = None, file_dict: dict = None, query: str = None, multiple_ok: bool = False)

Delete file specified by id, file dictionary or query string

Note. Be extra careful when calling this keyword!

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target file, needs to match 1 file unless parameter multiple_ok is set to True

  • multiple_ok – set to True if it is ok to perform delete on more than 1 file

Returns

how many files where deleted

Example:

${folder_id}=  Drive Get Folder Id   datafolder
${deleted}=    Drive Delete File   query=name contains '.json' and '${folder_id}' in parents
...            multiple_ok=True
drive_download_files(file_dict: dict = None, query: str = None, limit: int = None, timeout: float = None)

Download files specified by file dictionary or query string

Parameters start, limit and timeout are used only when downloading files defined by query parameter.

Parameters
  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target files, defaults to None

  • start – start index from which to start download files

  • limit – maximum amount of files that are downloaded, defaults to None

  • timeout – maximum allowed time in seconds for download process

Returns

list of downloaded files

Example:

${files}=    Drive Search Files    query=name contains '.json'
FOR    ${f}    IN    @{files}
    Run Keyword If  ${f}[size] < 2000  Drive Download Files  file_dict=${f}
END

${folder_id}=   Drive Get Folder Id   datafolder
Drive Download Files  query=name contains '.json' and '${folder_id}' in parents  recurse=True
drive_export_file(file_id: str = None, file_dict: dict = None, target_file: str = None, mimetype: str = 'application/pdf')

Export Google Drive file using Drive export links

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • target_file – name for the exported file

  • mimetype – export mimetype, defaults to “application/pdf”

Example:

${files}=  Drive Search Files  query=name contains 'my example worksheet'
Drive Export File  file_dict=${files}[0]
drive_get_folder_id(folder: str = None)

Get file id for the folder

Parameters

folder – name of the folder to identify, by default returns drive’s root folder id

Returns

file id of the folder

Example:

${root_id}=    Drive Get Folder Id   # returns Drive root folder id
${folder_id}=  Drive Get Folder Id  subdir
drive_move_file(file_id: str = None, file_dict: dict = None, query: str = None, folder: str = None, folder_id: str = None, multiple_ok: bool = False)

Move file specified by id, file dictionary or query string into target folder

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target file, needs to match 1 file

  • folder – name of the folder to move file into, is by default drive’s root folder id

  • folder_id – id of the folder to move file into, if set the folder parameter is ignored

  • multiple_ok – if True then moving more than 1 file

Returns

list of file ids

Raises

GoogleDriveError – if there are no files to move or target folder can’t be found

Example:

${source_id}=  Drive Get Folder Id  sourcefolder
${query}=      Set Variable  name contains '.json' and '${sourceid}' in parents
${files}=      Drive Move File  query=${query}  folder=target_folder  multiple_ok=True
drive_search_files(query: str = None, recurse: bool = False, folder_name: str = None) → list

Search Google Drive for files matching query string

Parameters
  • query – search string, defaults to None which means that all files and folders are returned

  • recurse – set to True if search should recursive

  • folder_name – search files in this directory

Raises

GoogleDriveError – if there is a request error

Returns

list of files

Example:

${files}=  Drive Search Files   query=name contains 'hello'
${files}=  Drive Search Files   query=modifiedTime > '2020-06-04T12:00:00'
${files}=  Drive Search Files   query=mimeType contains 'image/' or mimeType contains 'video/'
${files}=  Drive Search Files   query=name contains '.yaml'  recurse=True
${files}=  Drive Search Files   query=name contains '.yaml'  folder_name=datadirectory
drive_update_file(file_id: str = None, file_dict: dict = None, query: str = None, action: RPA.Cloud.Google.Update = <Update.star: 3>, multiple_ok: bool = False)

Update file specified by id, file dictionary or query string

Possible actions: - star - unstar - trash - untrash

Parameters
  • file_id – drive file id

  • file_dict – file dictionary returned by Drive Search Files

  • query – drive query string to find target file, needs to match 1 file

  • action – update action, default star file

  • multiple_ok – set to True if it is ok to perform update on more than 1 file

Returns

number of updated files

Example:

${folder_id}=  Drive Get Folder Id   datafolder
${updated}=    Drive Update File   query=name contains '.json' and '${folder_id}' in parents
...            action=star
...            multiple_ok=True
drive_upload_file(filename: str = None, folder: str = None, overwrite: bool = False, make_dir: bool = False) → dict

Upload files into Drive

Parameters
  • filename – name of the file to upload

  • folder – target folder for upload

  • overwrite – set to True if already existing file should be overwritten

  • make_dir – set to True if folder should be created if it does not exist

Raises

GoogleDriveError – if target_folder does not exist or trying to upload directory

Returns

uploaded file id

Example:

${file1_id}=  Drive Upload File   data.json  # Upload file to drive root
${file2_id}=  Drive Upload File   newdata.json  new_folder  make_dir=True
${file3_id}=  Drive Upload File   data.json  overwrite=True
global_scopes: list = []
init_drive_client(credentials_file: str = 'credentials.json', token_file: str = 'oauth.token', use_robocloud_vault: bool = False, scopes: list = None, save_token: bool = False) → None

Initialize Google Drive client

Parameters
  • credentials_file – filepath to credentials JSON

  • token_file – filepath to OAuth token file

  • use_robocloud_vault – if True the token is read from Robocloud

  • scopes – authenticated scopes, for example. [‘forms’, ‘spreadsheets’]

  • save_token – set to True if token should be saved to local file

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.ServiceNaturalLanguage

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Natural Language API

Link to Natural Language PyPI page.

analyze_sentiment(text_file: str, file_type: str = 'text', json_file: str = None, lang=None) → dict

Analyze sentiment in a text file

Parameters
  • text_file – source text file

  • json_file – json target to save result, defaults to None

  • lang – language code of the source, defaults to None

Returns

analysis response

classify_text(text_file, json_file, lang=None)

Classify text

Parameters
  • text_file – source text file

  • json_file – json target to save result, defaults to None

  • lang – language code of the source, defaults to None

Returns

classify response

clients: dict = {}
global_scopes: list = []
init_natural_language_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Natural Language client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.ServiceSheets

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Sheets API

You will have to grant the appropriate permissions to the service account you are using to authenticate with Google Sheets API. The IAM page in the console is here: https://console.cloud.google.com/iam-admin/iam/project

For more information about Google Sheets API link_.

clear_values(sheet_id: str, sheet_range: str) → None

Clear cell values for range of cells within a sheet

Parameters
  • sheet_id – target sheet

  • sheet_range – target sheet range

clients: dict = {}
create_sheet(title: str) → str

Create empty sheet with a title

Parameters

title – name as string

Returns

created sheet_id

get_values(sheet_id: str, sheet_range: str, value_render_option: str = 'UNFORMATTED_VALUE', datetime_render_option: str = 'FORMATTED_STRING') → list

Get values from the range in the sheet

Parameters
  • sheet_id – target sheet

  • sheet_range – target sheet range

  • value_render_option – how values should be represented in the output defaults to “UNFORMATTED_VALUE”

  • datetime_render_option – how dates, times, and durations should be represented in the output, defaults to “FORMATTED_STRING”

global_scopes: list = []
init_sheets_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Sheets client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

insert_values(sheet_id: str, sheet_range: str, values: list, major_dimension: str = 'COLUMNS', value_input_option: str = 'USER_ENTERED') → None

Insert values into sheet cells

Parameters
  • sheet_id – target sheet

  • sheet_range – target sheet range

  • values – list of values to insert into sheet

  • major_dimension – major dimension of the values, default COLUMNS

  • value_input_option – controls whether input strings are parsed or not, default USER_ENTERED

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.ServiceSpeechToText

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Speech-To-Text API

Possible input audio encodings:

  • ‘AMR’

  • ‘AMR_WB’

  • ‘ENCODING_UNSPECIFIED’

  • ‘FLAC’

  • ‘LINEAR16’

  • ‘MULAW’

  • ‘OGG_OPUS’

  • ‘SPEEX_WITH_HEADER_BYTE’

Link to Speech To Text PyPI page.

clients: dict = {}
global_scopes: list = []
init_speech_to_text_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Speech to Text client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

logger = None
recognize(audio_file_uri, encoding: str = 'FLAC', language_code: str = 'en_US', audio_channel_count=2)

Recognize text in the audio file

Parameters

audio_file_uri – Google Cloud Storage URI

Returns

recognized texts

region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.ServiceStorage

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Storage API

and Google Cloud Storage JSON API

You will have to grant the appropriate permissions to the service account you are using to authenticate with @google-cloud/storage. The IAM page in the console is here: https://console.cloud.google.com/iam-admin/iam/project

Link to Google Storage PyPI page.

clients: dict = {}
create_bucket(bucket_name: str)

Create Google Cloud Storage bucket

Parameters

bucket_name – name as string

Returns

bucket

delete_bucket(bucket_name: str)

Delete Google Cloud Storage bucket

Bucket needs to be empty before it can be deleted.

Parameters

bucket_name – name as string

delete_files(bucket_name: str, files: Any)

Delete files in the bucket

Files need to be object name in the bucket.

Parameters
  • bucket_name – name as string

  • files – single file, list of files or comma separated list of files

Returns

list of files which could not be deleted, or True if all were deleted

download_files(bucket_name: str, files: Any)

Download files from a bucket

Example files: files = {“mytestimg”: “image1.png”, “mydoc”: “google.pdf

Parameters
  • bucket_name – name as string

  • files – list of object names or dictionary of object names and target files

Returns

list of files which could not be downloaded, or True if all were downloaded

get_bucket(bucket_name: str)

Get Google Cloud Storage bucket

Parameters

bucket_name – name as string

Returns

bucket

global_scopes: list = []
init_storage_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Storage client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

list_buckets() → list

List Google Cloud Storage buckets

Returns

list of buckets

list_files(bucket_name: str)

List files in the bucket

Parameters

bucket_name – name as string

Returns

list of object names in the bucket

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

upload_file(bucket_name: str, filename: str, target_name: str)

Upload a file into a bucket

Parameters
  • bucket_name – name as string

  • filename – filepath to upload file

  • target_name – target object name

upload_files(bucket_name: str, files: dict)

Upload files into a bucket

Example files: files = {“mytestimg”: “image1.png”, “mydoc”: “google.pdf”}

Parameters
  • bucket_name – name as string

  • files – dictionary of object names and filepaths

class RPA.Cloud.Google.ServiceTextToSpeech

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Text-to-Speech API

Link to Text To Speech PyPI page.

clients: dict = {}
global_scopes: list = []
init_text_to_speech_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Text to Speech client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

list_supported_voices(language_code: str = None)

List supported voices for the speech

Parameters

language_code – voice languages to list, defaults to None (all)

Returns

list of supported voices

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

synthesize_speech(text, language='en-US', name='en-US-Standard-B', gender='MALE', encoding='MP3', target_file='synthesized.mp3')

Synthesize speech synchronously

Parameters
  • text – input text to synthesize

  • language – voice language, defaults to “en-US”

  • name – voice name, defaults to “en-US-Standard-B”

  • gender – voice gender, defaults to “MALE”

  • encoding – result encoding type, defaults to “MP3”

  • target_file – save synthesized output to file, defaults to “synthesized.mp3”

Returns

synthesized output in bytes

class RPA.Cloud.Google.ServiceTranslation

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Translation API

Link to Translation PyPI page.

clients: dict = {}
global_scopes: list = []
init_translation_client(service_credentials_file: str = None, project_identifier: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Translation client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • project_identifier – identifier for Translation project

  • use_robocloud_vault – use json stored into Robocloud Vault

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

translate(text: Any, source_language: str = None, target_language: str = None) → dict

Translate text

Parameters
  • text – text to translate

  • source_language – language code, defaults to None

  • target_language – language code, defaults to None

Returns

translated text

class RPA.Cloud.Google.ServiceVideoIntelligence

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Video Intelligence API

API supports only Google Cloud Storages URIs at the moment.

Link to Video Intelligence PyPI page.

annotate_video(video_uri: str = None, video_file: str = None, json_file: str = None, features: list = None)

Annotate video

Possible values for features:

  • FEATURE_UNSPECIFIED, Unspecified.

  • LABEL_DETECTION, Label detection. Detect objects, such as dog or flower.

  • SHOT_CHANGE_DETECTION, Shot change detection.

  • EXPLICIT_CONTENT_DETECTION, Explicit content detection.

  • SPEECH_TRANSCRIPTION, Speech transcription.

  • TEXT_DETECTION, OCR text detection and tracking.

  • OBJECT_TRACKING, Object detection and tracking.

  • LOGO_RECOGNITION, Logo detection, tracking, and recognition.

If video_uri is given then that is used even if video_file is None.

Parameters
  • video_uri – Google Cloud Storage URI

  • video_file – filepath to video

  • json_file – json target to save result, defaults to None

  • features – list of annotation features to detect, defaults to [“LABEL_DETECTION”, “SHOT_CHANGE_DETECTION”]

Returns

annotate result

clients: dict = {}
global_scopes: list = []
init_video_intelligence_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Video Intelligence client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.ServiceVision

Bases: RPA.Cloud.Google.GoogleBase

Class for Google Cloud Vision API

Link to Vision PyPI page.

annotate_image(image_uri: str, json_file: str = None) → dict

Annotate image

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

clients: dict = {}
detect_document(image_file: str, json_file: str = None) → dict

Detect document

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

detect_labels(image_file: str, json_file: str = None) → dict

Detect labels in the image

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

detect_text(image_file: str, json_file: str = None) → dict

Detect text in the image

Parameters
  • image_file – source image file

  • json_file – json target to save result, defaults to None

Returns

detection response

face_detection(image_uri: str, json_file: str = None) → dict

Detect faces

Parameters
  • image_uri – Google Cloud Storage URI

  • json_file – json target to save result, defaults to None

Returns

detection response

global_scopes: list = []
init_vision_client(service_credentials_file: str = None, use_robocloud_vault: bool = False) → None

Initialize Google Cloud Vision client

Parameters
  • service_credentials_file – filepath to credentials JSON

  • use_robocloud_vault – use json stored into Robocloud Vault

logger = None
region: str = None
robocloud_vault_name: str = None
robocloud_vault_secret_key: str = None
services: list = []
set_global_scopes(scopes: list = None)

Set global Google authentication scopes

Useful when using numerous services with different scopes

Parameters

scopes – list of authentication scopes

set_robocloud_vault(vault_name: str = None, vault_secret_key: str = None)

Set Robocloud Vault name and secret key name

Parameters
  • vault_name – Robocloud Vault name

  • vault_secret_key – Rococloud Vault secret key name

class RPA.Cloud.Google.Update

Bases: enum.Enum

Possible file update actions.

star = 3
trash = 1
unstar = 4
untrash = 2
RPA.Cloud.Google.google_dependency_required(f)
RPA.Cloud.Google.to_action(value)

Convert value to Update enum.