Python API
Google
- class RPA.Cloud.Google.Google(service_account: str | None = None, vault_name: str | None = None, vault_secret_key: str | None = None, cloud_auth_type: str = 'serviceaccount')
Google is a library for operating with Google API endpoints.
Installation
Usage requires the following steps:
Create a GCP project
Enable approriate APIs
Create credentials (OAuth or service account)
Install
rpaframework-google
package
Check the latest package version from PyPI.
Google authentication
Authentication for Google is set with service account JSON file which can be given to the library in three different ways or with OAuth2 token, which is used for OAuth authentication.
See library authentication examples for more information.
Basic usage examples
Python
from RPA.Cloud.Google import Google library = Google() service_account = '/path/to/service_account.json' library.init_vision(service_account) library.init_text_to_speech(service_account) response = library.detect_text('imagefile.png', 'result.json') library.synthesize_speech('I want this said aloud', target_file='said.mp3')
Robot Framework
*** Settings *** Library RPA.Cloud.Google *** Variables *** ${SERVICE_ACCOUNT} ${/}path${/}to${/}service_account.json ${BUCKET_NAME} testbucket12213123123 *** Tasks *** Upload a file into a new storage bucket [Setup] Init Storage ${SERVICE_ACCOUNT} Create Storage Bucket ${BUCKET_NAME} Upload Storage File ${BUCKET_NAME} ... ${/}path${/}to${/}file.pdf ... myfile.pdf @{files} List Storage Files ${BUCKET_NAME} FOR ${file} IN @{files} Log ${file} END
- ROBOT_LIBRARY_DOC_FORMAT = 'REST'
- ROBOT_LIBRARY_SCOPE = 'GLOBAL'
- add_attachment_to_message(mimeMessage, attachment)
Keyword for sharing drive file or folder.
Parameters file_id, file_dict, query and source can be used to select files to which sharing is added to.
If share is added to a folder, all files within that folder get same sharing permissions.
- Parameters:
file_id – drive file id
file_dict – file dictionary returned by Search Drive Files
query – drive query string to find target file, needs to match 1 file
source – name of the folder to search files in, is by default drive’s root folder
email – user or group email address if share type is DriveType.USER or DriveType.GROUP
domain – domain name if share type is DriveType.DOMAIN
role – see
DriveRole
enum for possible values, defaults to DriveRole.READERshare_type – see
DriveType
enum for possible values, defaults to DriveType.USERnotification – whether to send notificatin email, defaults to False
notification_message – optional message to include with the notification
- Returns:
share response dictionary containing ‘file_id’ and ‘permission_id’
Example:
# Add file share for a email address with email notification Add Drive Share ... query=name = 'okta.png' ... email=robocorp.tester@gmail.com ... notification=True ... notification_message=Hello. I have shared 'okta.png' with you for review. # Add file share for a domain Add Drive Share ... query=name = 'okta.png' ... domain=robocorp.com # Add folder share for a email address ${folder}= Create Drive Directory attachments-for-the-task ${share}= Add Drive Share ... file_id=${folder}[id] ... email=robocorp.tester@gmail.com ... role=writer Log To Console Share details: ${share}[file_id], ${share}[permission_id]
- analyze_sentiment(text: str | None = None, text_file: str | None = None, file_type: TextType = TextType.TEXT, json_file: str | None = None, lang: str | None = None) Dict
Analyze sentiment in a text file
- Parameters:
text – source text
text_file – source text file
file_type – type of text, PLAIN_TEXT (default) or HTML
json_file – json target to save result, defaults to None
lang – language code of the source, defaults to None
- Returns:
analysis response
For list of supported languages: https://cloud.google.com/natural-language/docs/languages
Examples
Robot Framework
${result}= Analyze Sentiment ${text} ${result}= Analyze Sentiment text_file=${CURDIR}${/}test.txt
- annotate_image(image_file: str, image_uri: str, json_file: str | None = None) Dict
Annotate image
- Parameters:
image_file – source image file path
image_uri – Google Cloud Storage URI
json_file – json target to save result
- Returns:
detection response
Examples
Robot Framework
${result}= Annotate Image image_file=${CURDIR}${/}test.png ... json_file=${CURDIR}${/}result.json
- annotate_video(video_file: str | None = None, video_uri: str | None = None, features: str | None = None, output_uri: str | None = None, json_file: str | None = None, timeout: int = 300) Dict
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 given.
- Parameters:
video_file – local file path to input video
video_uri – Google Cloud Storage URI to input video
features – list of annotation features to detect, defaults to LABEL_DETECTION,SHOT_CHANGE_DETECTION
output_uri – Google Cloud Storage URI to store response json
json_file – json target to save result
timeout – timeout for operation in seconds
- Returns:
annotate result
Examples
Robot Framework
${result}= Annotate Video video_uri=gs://videointelligence/movie.mp4 ... features=TEXT_DETECTION,LABEL_DETECTION ... output_uri=gs://videointelligence/movie_annotations.json ... json_file=${CURDIR}${/}videoannotations.json
- classify_text(text: str | None = None, text_file: str | None = None, file_type: TextType = TextType.TEXT, json_file: str | None = None, lang: str | None = None) Dict
Classify text
- Parameters:
text – source text
text_file – source text file
file_type – type of text, PLAIN_TEXT (default) or HTML
json_file – json target to save result, defaults to None
lang – language code of the source, defaults to None
- Returns:
classify response
For list of supported languages: https://cloud.google.com/natural-language/docs/languages
Examples
Robot Framework
${result}= Classify Text ${text} ${result}= Classify Text text_file=${CURDIR}${/}test.txt
- clear_sheet_values(spreadsheet_id: str, sheet_range: str) Dict
Clear cell values for range of cells within a spreadsheet
- Parameters:
spreadsheet_id – target spreadsheet
sheet_range – target sheet range
- Returns:
operation result
Examples
Python
result = GOOGLE.clear_sheet_values(spreadsheet_id, "A1:C1")
Robot Framework
${result}= Clear Sheet Values ${SPREADSHEET_ID} A1:C1
- copy_sheet(spreadsheet_id: str, source_sheet_name: str, new_sheet_name: str, insertSheetIndex: int | None = None)
Copy sheet into the spreadsheet as new sheet
- Parameters:
spreadsheet_id – id of the spreadsheet
source_sheet_name – name of the source sheet
new_sheet_name – name for the new sheet
insertSheetIndex – zero based index where the new sheet should be inserted, defaults to None
- Returns:
operation result as an dictionary
Examples
Python
result = GOOGLE.copy_sheet( spreadsheet_id, "Existing sheet", "Copy of existing sheet" )
Robot Framework
${result}= Copy Sheet ... ${SPREADSHEET_ID} ... Existing sheet ... Copy of existing sheet
- copy_spreadsheet(spreadsheet_id: str, target_spreadsheet_id: str) Dict
Copy spreadsheet to target spreadsheet
NOTE: service account user must have access also to target spreadsheet
- Parameters:
spreadsheet_id – ID of the spreadsheet to copy
target_spreadsheet_id – ID of the target spreadsheet
- Returns:
operation result
Examples
Python
result = GOOGLE.copy_spreadsheet( spreadsheet_id, source_spreadsheet_id, target_spreadsheet_id)
Robot Framework
${result}= Copy Spreadsheet ${SPREADSHEET_ID} ${ANOTHER_SPREADSHEET_ID}
- create_drive_directory(folder: str | None = None, parent_folder: str | None = None) Dict
Create new directory to Google Drive
- Parameters:
folder – name for the new directory
parent_folder – top level directory for new directory
- Returns:
dictionary containing folder ID and folder URL
Example:
${folder}= Create Drive Directory example-folder Log To Console Google Drive folder ID: ${folder}[id] Log To Console Google Drive folder URL: ${folder}[url]
- create_message(to: str, subject: str, message_text: str, attachments: list | None = None, html: bool = False)
Create a message for an email.
- Parameters:
to – message recipient
subject – message subject
message_text – message body text
attachment – list of files to add as message attachments
html – set to True if message body is HTML (default False, plain text)
- Returns:
An object containing a base64url encoded email object
- create_sheet(spreadsheet_id: str, sheet_name: str)
Create sheet into the spreadsheet
- Parameters:
spreadsheet_id – id of the spreadsheet
sheet_name – name for the new sheet
- Returns:
operation result as an dictionary
Examples
Python
result = GOOGLE.create_sheet(spreadsheet_id, "New sheet")
Robot Framework
${result}= Create Sheet ${SPREADSHEET_ID} New sheet
- create_spreadsheet(title: str) str
Create empty sheet with a title
- Parameters:
title – name as string
- Returns:
created spreadsheet_id
Examples
Python
result = GOOGLE.create_spreadsheet("name of the spreadsheet")
Robot Framework
${result}= Create Sheet Example Sheet
- create_storage_bucket(bucket_name: str) Dict
Create Google Cloud Storage bucket
- Parameters:
bucket_name – name as string
- Returns:
bucket
Examples
Robot Framework
${result}= Create Storage Bucket visionfolder
- delete_drive_file(file_id: str | None = None, file_dict: dict | None = None, query: str | None = None, multiple_ok: bool = False, suppress_errors: bool = False) int
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 Search Drive 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
suppress_errors – on True will log warning message instead of raising an exception, defaults to False
- Returns:
how many files where deleted
Example:
${folder_id}= Get Drive Folder Id datafolder ${deleted}= Delete Drive File query=name contains '.json' and '${folder_id}' in parents ... multiple_ok=True
- delete_sheet(spreadsheet_id: str, sheet_name: str)
Delete a sheet from the spreadsheet.
- Parameters:
spreadsheet_id – id of the spreadsheet
sheet_name – name of the sheet to delete
- Returns:
operation result as an dictionary
Examples
Python
result = GOOGLE.delete_sheet(spreadsheet_id, "Sheet1")
Robot Framework
${result}= Delete Sheet ${SPREADSHEET_ID} Sheet1
- delete_storage_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
Examples
Robot Framework
${result}= Delete Storage Bucket visionfolder
- delete_storage_files(bucket_name: str, files: Any) List
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
Examples
Robot Framework
${result}= Delete Storage Files ${BUCKET_NAME} file1,file2
- detect_document(image_file: str | None = None, image_uri: str | None = None, json_file: str | None = None) Dict
Detect document
- Parameters:
image_file – source image file path
image_uri – Google Cloud Storage URI
json_file – json target to save result
- Returns:
detection response
Examples
Robot Framework
${result}= Detect Document image_file=${CURDIR}${/}test.png ... json_file=${CURDIR}${/}result.json
- detect_labels(image_file: str | None = None, image_uri: str | None = None, json_file: str | None = None) Dict
Detect labels in the image
- Parameters:
image_file – source image file path
image_uri – source image uri
json_file – json target to save result
- Returns:
detection response
Examples
Robot Framework
${result}= Detect Labels image_file=${CURDIR}${/}test.png ... json_file=${CURDIR}${/}result.json
- detect_tables(spreadsheet_id: str, sheet_name: str | None = None)
Detect tables in the sheet.
- Parameters:
spreadsheet_id – id of the spreadsheet
sheet_name – name of the sheet, or leave None for all sheets
- Returns:
tables arranged by sheets
- detect_text(image_file: str | None = None, image_uri: str | None = None, json_file: str | None = None) Dict
Detect text in the image
- Parameters:
image_file – source image file path
image_uri – Google Cloud Storage URI
json_file – json target to save result
- Returns:
detection response
Examples
Robot Framework
${result}= Detect Text image_file=${CURDIR}${/}test.png ... json_file=${CURDIR}${/}result.json
- download_drive_files(file_dict: dict | None = None, query: str | None = None, source: str | None = None, limit: int | None = None, timeout: float | None = None) List
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 Search Drive Files
query – drive query string to find target files, defaults to None
source – source directory where query is executed
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}= Search Drive Files query=name contains '.json' FOR ${f} IN @{files} IF ${f}[size] < 2000 Download Drive Files file_dict=${f} END END ${folder_id}= Get Drive Folder Id datafolder Download Drive Files query=name contains '.json' and '${folder_id}' in parents
- download_storage_files(bucket_name: str, files: Any) List
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
Examples
Robot Framework
${result}= Download Storage Files ${BUCKET_NAME} test1.txt,test2.txt
- export_drive_file(file_id: str | None = None, file_dict: dict | None = None, target_file: str | None = None, mimetype: str = 'application/pdf') str
Export Google Drive file using Drive export links
- Parameters:
file_id – drive file id
file_dict – file dictionary returned by Search Drive Files
target_file – name for the exported file
mimetype – export mimetype, defaults to “application/pdf”
- Returns:
file path to the exported file
Example:
${files}= Drive Search Files query=name contains 'my example worksheet' Export Drive File file_dict=${files}[0]
- face_detection(image_file: str | None = None, image_uri: str | None = None, json_file: str | None = None) Dict
Detect faces
- Parameters:
image_file – source image file path
image_uri – Google Cloud Storage URI
json_file – json target to save result
- Returns:
detection response
Examples
Robot Framework
${result}= Face Detection image_uri=gs://vision/faces.png ... json_file=${CURDIR}${/}result.json
- generic_spreadsheet_batch_update(spreadsheet_id: str, body: Dict)
This keyword allows to do generic batch update to the spreadsheet.
For more information on the batch update: https://googleapis.github.io/google-api-python-client/docs/dyn/sheets_v4.spreadsheets.html#create
List of possible requests actions (body can contain multiple at the same time):
addBanding
addChart
addConditionalFormatRule
addDataSource
addDimensionGroup
addFilterView
addNamedRange
addProtectedRange
addSheet (keyword
Create sheet
)addSlicer
appendCells
appendDimension
autoFill
autoResizeDimensions
clearBasicFilter
copyPaste
createDeveloperMetadata
cutPaste
deleteBanding
deleteConditionalFormatRule
deleteDataSource
deleteDeveloperMetadata
deleteDimension
deleteDimensionGroup
deleteDuplicates
deleteEmbeddedObject
deleteFilterView
deleteNamedRange
deleteProtectedRange
deleteRange
deleteSheet (keyword
Delete sheet
)duplicateFilterView
duplicateSheet (keyword
Copy sheet
)findReplace
insertDimension
insertRange
mergeCells
moveDimension
pasteData
randomizeRange
refreshDataSource
repeatCell
setBasicFilter
setDataValidation
sortRange
textToColumns
trimWhitespace
unmergeCells
updateBanding
updateBorders
updateCells
updateChartSpec
updateConditionalFormatRule
updateDataSource
updateDeveloperMetadata
updateDimensionGroup
updateDimensionProperties
updateEmbeddedObjectBorder
updateEmbeddedObjectPosition
updateFilterView
updateNamedRange
updateProtectedRange
updateSheetProperties (keyword
Rename sheet
)updateSlicerSpec
updateSpreadsheetProperties
- Parameters:
spreadsheet_id – id of the spreadsheet
body – body of the batch update request
- Returns:
operation result as an dictionary
Examples
Python
body = {"requests": {"deleteSheet": {"sheetId": "333555666"}}} result = GOOGLE.generic_spreadsheet_batch_update(spreadsheet_id, body)
Robot Framework
${body}= Evaluate {"requests": {"deleteSheet": {"sheetId": "333555666"}}} ${result}= Generic Spreadsheet Batch Update ${SPREADSHEET_ID} ${body}
- get_all_sheet_values(spreadsheet_id: str, sheet_name: str | None = None, value_render_option: str = 'UNFORMATTED_VALUE', datetime_render_option: str = 'FORMATTED_STRING') List
Get values from the range in the spreadsheet
- Parameters:
spreadsheet_id – target spreadsheet
sheet_name – target sheet (default first sheet)
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”
- Returns:
operation result
Examples
Python
result = GOOGLE.get_all_sheet_values(spreadsheet_id)
Robot Framework
${values}= Get All Sheet Values ${SHEET_ID} sheet1
- get_document_entities(document: Document) List
Helper keyword for getting document entities from a
Process Document
response object.For examples. see
Process Document
keyword- Parameters:
document – the document response object
- Returns:
detected entities in the document response as a list
- get_document_languages(document: Document) List
Helper keyword for getting detected languages from a
Process Document
response object.For examples. see
Process Document
keyword- Parameters:
document – the document response object
- Returns:
detected languages in the document response as a list
- get_drive_file_by_id(file_id: str, suppress_errors: bool = False) Dict
Get file dictionary by its file id.
- Parameters:
file_id – id of the file in the Google Drive
suppress_errors – on True will log warning message instead of raising an exception, defaults to False (exception is raised)
- Returns:
dictionary containing file information
Example:
${file_dict}= Get Drive File By ID file_id=${FILE_ID}
- get_drive_folder_id(folder: str | None = None, parent_folder: str | None = None, details: bool = False) str
Get file id for the folder
- Parameters:
folder – name of the folder to identify, by default returns drive’s root folder id
parent_folder – can be used to narrow search by giving parent folder name
details – on True will return folder dictionary, on False (default) folder id is returned
- Returns:
file id of the folder or file dictionary when details = True
Example:
${root_id}= Get Drive Folder Id # returns Drive root folder id ${folder_id}= Get Drive Folder Id subdir
- get_sheet_by_name(spreadsheet_id: str, sheet_name: str)
- get_sheet_formulas(spreadsheet_id: str, sheet_name: str)
Get formulas from the sheet.
- Parameters:
spreadsheet_id – id of the spreadsheet
sheet_name – name of the sheet
- Returns:
_description_
- get_sheet_values(spreadsheet_id: str, sheet_range: str | None = None, value_render_option: str = 'UNFORMATTED_VALUE', datetime_render_option: str = 'FORMATTED_STRING') List
Get values from the range in the spreadhsheet
- Parameters:
spreadsheet_id – target spreadsheet
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”
- Returns:
operation result
Examples
Python
result = GOOGLE.get_sheet_values(spreadsheet_id, "A1:C1")
Robot Framework
${values}= Get Sheet Values ${SPREADSHEET_ID} A1:C1
- get_spreadsheet_basic_information(spreadsheet_id: str) List
Get title, id, url and sheets information from the spreadsheet.
- Parameters:
spreadsheet_id – ID of the spreadsheet
- Returns:
operation result as an dictionary
- get_spreadsheet_details(spreadsheet_id: str) Dict
Returns spreadsheet information as a dictionary.
- Parameters:
spreadsheet_id – ID of the spreadsheet
- Returns:
operation result as an dictionary
- get_storage_bucket(bucket_name: str) Dict
Get Google Cloud Storage bucket
- Parameters:
bucket_name – name as string
- Returns:
bucket
Examples
Robot Framework
${result}= Get Bucket visionfolder
- handle_mimetypes(parsed_parts, part, msg, folder_name)
- init_apps_script(service_account: str | None = None, credentials: str | None = None, use_robocorp_vault: bool | None = None, scopes: list | None = None, token_file: str | None = None) None
Initialize Google Apps Script client
- Parameters:
service_account – file path to service account file
credentials – file path to credentials file
use_robocorp_vault – use credentials in Robocorp Vault
scopes – list of extra authentication scopes
token_file – file path to token file
- init_document_ai(service_account: str | None = None, region: str | None = 'us', use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Document AI client
- Parameters:
service_account – file path to service account file
region – region of the service
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
Robot Framework example:
# Init using Service Account from a file Init Document AI ${CURDIR}${/}service_account.json region=eu # Init using OAuth token from a file and default "us" region Init Document AI ${CURDIR}${/}token.json # Init using service account file from the Robocorp Vault Set Robocorp Vault ... vault_name=DocumentAI ... vault_secret_key=google-sa Init Document AI region=eu use_robocorp_vault=True
Python example:
GOOGLE = Google() GOOGLE.set_robocorp_vault("DocumentAI", "google-sa") GOOGLE.init_document_ai(region="eu", use_robocorp_vault=True)
- init_drive(service_account: str | None = None, credentials: str | None = None, use_robocorp_vault: bool | None = None, scopes: list | None = None, token_file: str | None = None) None
Initialize Google Drive client
- Parameters:
service_account – file path to service account file
credentials – file path to credentials file
use_robocorp_vault – use credentials in Robocorp Vault
scopes – list of extra authentication scopes
token_file – file path to token file
- init_gmail(service_account: str | None = None, credentials: str | None = None, use_robocorp_vault: bool | None = None, scopes: list | None = None, token_file: str | None = None) None
Initialize Google Gmail client
- Parameters:
service_account – file path to service account file
credentials – file path to credentials file
use_robocorp_vault – use credentials in Robocorp Vault
scopes – list of extra authentication scopes
token_file – file path to token file
- init_natural_language(service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Natural Language client
- Parameters:
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- init_sheets(service_account: str | None = None, credentials: str | None = None, use_robocorp_vault: bool | None = None, scopes: list | None = None, token_file: str | None = None) None
Initialize Google Sheets client
- Parameters:
service_account – file path to service account file
credentials – file path to credentials file
use_robocorp_vault – use credentials in Robocorp Vault
scopes – list of extra authentication scopes
token_file – file path to token file
- init_speech_to_text(service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Speech to Text client
- Parameters:
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- init_storage(service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Storage client
- Parameters:
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- init_text_to_speech(service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Text to Speech client
- Parameters:
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- init_translation(project_identifier: str, service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Translation client
- Parameters:
project_identifier – identifier for Translation project
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- init_video_intelligence(service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Video Intelligence client
- Parameters:
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- init_vision(service_account: str | None = None, use_robocorp_vault: bool | None = None, token_file: str | None = None) None
Initialize Google Cloud Vision client
- Parameters:
service_account – file path to service account file
use_robocorp_vault – use credentials in Robocorp Vault
token_file – file path to token file
- insert_sheet_values(spreadsheet_id: str, sheet_range: str, values: list, major_dimension: str = 'COLUMNS', value_input_option: str = 'USER_ENTERED') Dict
Insert values into sheet cells
- Parameters:
spreadsheet_id – target spreadsheet
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
- Returns:
operation result
Examples
Python
values = [[11, 12, 13], ['aa', 'bb', 'cc']] result = GOOGLE.insert_sheet_values(spreadsheet_id, "A:C", values)
Robot Framework
${values} Evaluate [[11, 12, 13], ['aa', 'bb', 'cc']] ${result}= Insert Sheet Values ${SPREADSHEET_ID} A:B ${values} ${result}= Insert Sheet Values ${SPREADSHEET_ID} A:B ${values} ROWS
- list_messages(user_id: str, query: str, folder_name: str | None = None, label_ids: list | None = None, max_results: int | None = None, include_json: bool = False, include_spam: bool = False)
List messages
- Parameters:
user_id – user’s email address. The special value me can be used to indicate the authenticated user.
query – message query
folder_name – path where attachments are saved, default current directory
label_ids – message label ids
max_results – maximum number of message to return
include_json – include original response json
include_spam – include messages from SPAM and TRASH
- Returns:
messages
Example:
${messages}= List Messages me ... from:mika@robocorp.com ... folder_name=${CURDIR}${/}target ... include_json=True FOR ${msg} IN @{messages} Log Many ${msg} END
- list_processors(project_id: str, region: str) List
List existing document AI processors from given project and region.
Requires documentai.processors.list permission.
- Parameters:
project_id – Google Cloud project ID
region – Google Cloud region of the processor
- Returns:
list of available processors as a list
Robot Framework example:
@{processors}= List Processors ${PROJECT_ID} eu FOR ${p} IN @{processors} # name: projects/PROJECT_ID/locations/REGION/processors/PROCESSOR_ID Log To Console Processor name: ${p.name} Log To Console Processor type: ${p.type_} Log To Console Processor display name: ${p.display_name} END
Python example:
processors = GOOGLE.list_processors(PROJECT_ID, "eu") for p in processors: print(f"Processor name: {p.name}") print(f"Processor type: {p.type_}") print(f"Processor name: {p.display_name}")
Keyword for listing shared files in the source folder.
Alias keyword for
Search Drive Files
which can be used to list only files which have been shared.- Parameters:
query – drive query string to find target files
source – source directory where query is executed
- Returns:
list of shared files
Example:
${shared}= List Shared Drive Files source=subfolder FOR ${file} IN @{shared} Log To Console ${file} END
- list_storage_buckets() List
List Google Cloud Storage buckets
- Returns:
list of buckets
Examples
Robot Framework
${buckets}= List Storage Buckets FOR ${bucket} IN @{buckets} Log ${bucket} END
- list_storage_files(bucket_name: str) List
List files in the bucket
- Parameters:
bucket_name – name as string
- Returns:
list of object names in the bucket
Examples
Robot Framework
${files}= List Storage Files ${BUCKET_NAME} FOR ${bucket} IN @{files} Log ${file} END
- list_supported_voices(language_code: str | None = None) List
List supported voices for the speech
- Parameters:
language_code – voice languages to list, defaults to None (all)
- Returns:
list of supported voices
Examples
Robot Framework
${result}= List Supported Voices en-US
- load_document_response(filepath: str) Document
Loads the binary object saved by
Save Document Response
intodocumentai.Document
format which is accessible by helper keywords.- Parameters:
filepath – source file to read binary document object from
- Returns:
processed document response object
Robot Framework example:
# load previously saved response ${document}= Load Document Response ${CURDIR}${/}google_processed.response ${entities}= Get Document Entities ${document}
Python example:
document = GOOGLE.load_document_response("google_doc.response") entities = GOOGLE.get_document_entities(document) for ent in entities: print(ent)
- move_drive_file(file_id: str | None = None, file_dict: dict | None = None, query: str | None = None, source: str | None = None, target: str | None = None, multiple_ok: bool = False) List
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 Search Drive Files
query – drive query string to find target file, needs to match 1 file
source – name of the folder to move file from, is by default drive’s root folder id
target – name of the folder to move file into, is by default drive’s root folder id
multiple_ok – if True then moving more than 1 file
- Returns:
list of file ids
Example:
${source_id}= Get Drive Folder Id sourcefolder ${query}= Set Variable name contains '.json' and '${sourceid}' in parents ${files}= Move Drive File query=${query} folder=target_folder multiple_ok=True
- parse_parts(msg_id, msg, parts, folder_name)
Utility function that parses the content of an email partition
- process_document(project_id: str, region: str, processor_id: str, file_path: str, mime_type: str | None = None) Document
Process document in the Google Cloud platform using given document processor ID within given project and region.
For a full list of Document response object attributes, please reference this page.
- Parameters:
project_id – Google Cloud project ID
region – Google Cloud region of the processor
processor_id – ID of the document processor
file_path – filepath of the document to process
mime_type – given mime type of document (optional), if not given it is auto detected
- Returns:
processed document response object
Robot Framework example:
${document}= Process Document ... project_id=${GOOGLE_PROJECT_ID} ... region=eu ... processor_id=${RECEIPT_PROCESSOR_ID} ... file_path=${CURDIR}${/}mydocument.pdf ${entities}= Get Document Entities ${document} FOR ${ent} IN @{entities} Log To Console Entity: ${ent} END ${languages}= Get Document Languages ${document} Log To Console Languages: ${languages}
Python example:
document = GOOGLE.process_document( project_id=PROJECT_ID, region="eu", processor_id=PROCESSOR_ID, file_path="./files/mydocument.pdf", ) entities = GOOGLE.get_document_entities(document) for ent in entities: print(ent) languages = GOOGLE.get_document_languages(document) for lang in languages: print(lang)
- recognize_text_from_audio(audio_file: str | None = None, audio_uri: str | None = None, encoding: str | None = None, language_code: str = 'en_US', audio_channel_count: int = 2, sample_rate: int | None = None) Dict
Recognize text in the audio file
- Parameters:
audio_file – local audio file path
audio_uri – Google Cloud Storage URI
encoding – audio file encoding
language_code – language in the audio
audio_channel_count – number of audio channel
sample_rate – rate in hertz, for example 16000
- Returns:
recognized texts
Examples
Robot Framework
${result}= Recognize Text From Audio audio_file=${CURDIR}${/}test.mp3
Keyword for removing all shares from selected files (only owner permission is retained).
- Parameters:
file_id – drive file id
file_dict – file dictionary returned by Search Drive Files
query – drive query string to find target files
suppress_errors – on True will log warning message instead of raising an exception, defaults to False (exception is raised)
- Returns:
list of dictionaries containing information of file permissions removed
Example:
${removed}= Remove All Drive Shares file_id=${FOLDER_ID}
Keyword for removing share from file or folder based on criteria.
Parameters file_id, file_dict, query and source can be used to select files from which sharing is removed.
Parameters email, domain or permission_id can be used to select which share is removed from selected files.
- Parameters:
email – email address of the permission to remove
domain – domain name of the permission to remove
permission_id – id of the permission to remove
file_id – drive file id
file_dict – file dictionary returned by Search Drive Files
query – drive query string to find target files
source – name of the folder to search files in, is by default drive’s root folder
suppress_errors – on True will log warning message instead of raising an exception, defaults to False (exception is raised)
- Returns:
list of dictionaries containing information of file permissions removed
Example:
# Remove domain shares for files in the folder ${FOLDER_NAME} ${removed}= Remove Drive Share By Criteria ... domain=robocorp.com ... source=${FOLDER_NAME} # Remove email share for a file ${removed}= Remove Drive Share By Criteria ... query=name = 'okta.png' ... email=robocorp.tester@gmail.com
Keyword for removing share permission of file or folder permission id.
Parameters file_id, file_dict, query and source can be used to select files from which sharing is removed.
- Parameters:
permission_id – id of the permission to remove
file_id – drive file id
file_dict – file dictionary returned by Search Drive Files
query – drive query string to find target file, needs to match 1 file
source – name of the folder to search files in, is by default drive’s root folder
suppress_errors – on True will log warning message instead of raising an exception, defaults to False (exception is raised)
- Returns:
dictionary of permission response
Example:
${share}= Add Drive Share ... query=name = 'sharable-files' and mimeType = 'application/vnd.google-apps.folder' ... email=robocorp.tester@gmail.com # # actions on shared files in the folder 'shareable-files' .... # Remove Drive Share By Permission Id ${share}[permission_id] ${share}[file_id]
- rename_sheet(spreadsheet_id: str, sheet_name: str, new_sheet_name: str)
Rename sheet in the spreadsheet
- Parameters:
spreadsheet_id – id of the spreadsheet
sheet_name – existing name of the sheet
new_sheet_name – name for the new sheet
- Returns:
operation result as an dictionary
Examples
Python
result = GOOGLE.rename_sheet(spreadsheet_id, "Sheet1", "New name")
Robot Framework
${result}= Rename Sheet ${SPREADSHEET_ID} Sheet1 New name
- run_script(script_id: str, function_name: str, parameters: dict | None = None) None
Run the Google Apps Script function
- 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}
- save_document_response(document: Document, filepath: str) None
Save
Process Document
response into a binary file.- Parameters:
document – response document object
filepath – target file to save binary object into
Robot Framework example:
${document}= Process Document ... project_id=101134120147 ... region=eu ... processor_id=${RECEIPT_PROCESSOR} ... file_path=${file_in} # save response for later Save Document Response ${CURDIR}${/}google_processed.response
Python example:
document = GOOGLE.process_document( project_id=PROJECT_ID, region="eu", processor_id=PROCESSOR_ID, file_path="./files/receipt1.jpg", ) GOOGLE.save_document_response(document, "receipt.response")
- search_drive_files(query: str | None = None, recurse: bool = False, source: str | None = 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
source – source directory where query is executed
- Returns:
list of files
Example:
${files}= Search Drive Files query=name contains 'hello' ${files}= Search Drive Files query=modifiedTime > '2020-06-04T12:00:00' ${files}= Search Drive Files query=mimeType contains 'image/' or mimeType contains 'video/' ${files}= Search Drive Files query=name contains '.yaml' recurse=True ${files}= Search Drive Files query=name contains '.yaml' source=datadirectory
- send_message(sender: str, to: str, subject: str, message_text: str, attachments: list | None = None, html: bool = False)
Send an email message.
- Parameters:
sender – message sender
to – message recipient
subject – message subject
message_text – message body text
attachment – list of files to add as message attachments
html – set to True if message body is HTML (default False, plain text)
- Returns:
sent message
Example:
${attachments}= Create List ... ${CURDIR}${/}random.txt ... ${CURDIR}${/}source.png Send Message me ... mika@robocorp.com ... message subject ... body of the message ... ${attachments}
- set_audio_type(audio_file, audio_uri)
- set_headers_to_message_dict(payload, message_id, response)
- set_image_type(image_file: str | None = None, image_uri: str | None = None)
- set_list_parameters(user_id, query, label_ids, max_results, include_spam)
- set_robocorp_vault(vault_name: str | None = None, vault_secret_key: str | None = None, auth_type: str = 'serviceaccount')
Set Robocorp Vault name and secret key name :param vault_name: Robocorp Vault name :param vault_secret_key: Robocorp Vault secret key name :param auth_type: either serviceaccount or token
- synthesize_speech(text: str, language: str = 'en-US', name: str = 'en-US-Standard-B', gender: str = 'MALE', encoding: str = 'MP3', target_file: str = 'synthesized.mp3') List
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
Examples
Robot Framework
${result}= Synthesize Speech ${text}
- to_A1_notation(column_number: int, row_number: int)
Convert a column number and a row number into a cell reference.
- Parameters:
column_number – column number to convert
row_number – row number to convert
- Returns:
cell reference string
- to_column_letter(number: int)
Convert a column number into a column letter(s).
- Parameters:
number – column number to convert
- Returns:
column letter(s)
- translate(text: list | str, source_language: str | None = None, target_language: str | None = None, mime_type: TextType | None = None) Dict
Translate text
- Parameters:
text – text to translate
source_language – language code
target_language – language code
mime_type – text or html
- Returns:
translated text
Examples
Robot Framework
${result}= Translate ${TEXT} target_language=de
- update_drive_file(file_id: str | None = None, file_dict: dict | None = None, query: str | None = None, source: str | None = None, action: UpdateAction = UpdateAction.star, multiple_ok: bool = False) int
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
source – source directory where query is executed
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}= Get Drive Folder Id datafolder ${updated}= Update Drive File query=name contains '.json' and '${folder_id}' in parents ... action=star ... multiple_ok=True
- update_sheet_values(spreadsheet_id: str, sheet_range: str, values: list, major_dimension: str = 'COLUMNS', value_input_option: str = 'USER_ENTERED') Dict
Insert values into sheet cells
- Parameters:
spreadsheet_id – target spreadsheet
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
- Returns:
operation result
Examples
Python
row_data = [[11, 12, 13], ['aa', 'bb', 'cc']] result = GOOGLE.update_sheet_values( spreadsheet_id, "A1:C1", row_data, "ROWS )
Robot Framework
${row} Evaluate [[22, 33 ,44]] ${result}= Update Sheet Values ... ${SPREADSHEET_ID} ... A6:C6 ... ${row} ... ROWS
- upload_drive_file(filename: str | None = None, folder: str | None = None, overwrite: bool = False, make_dir: bool = False) str
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
- Returns:
uploaded file id
Example:
${file1_id}= Upload Drive File data.json # Upload file to drive root ${file2_id}= Upload Drive File newdata.json new_folder make_dir=True ${file3_id}= Upload Drive File data.json overwrite=True
- upload_storage_file(bucket_name: str, filename: str, target_name: str) None
Upload a file into a bucket
- Parameters:
bucket_name – name as string
filename – filepath to upload file
target_name – target object name
Examples
Robot Framework
Upload Storage File ${BUCKET_NAME} ... ${CURDIR}${/}test.txt test.txt
- upload_storage_files(bucket_name: str, files: dict) None
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
Examples
Robot Framework
${files}= Create Dictionary ... test1.txt ${CURDIR}${/}test1.txt ... test2.txt ${CURDIR}${/}test2.txt Upload Storage Files ${BUCKET_NAME} ${files}