RPA.Cloud.Google
module RPA.Google
class RPA.Cloud.Google.Google
Google is a library for operating with Google API endpoints.
Usage requires the following steps:
- Create a GCP project
- Enable approriate APIs
- Create credentials (OAuth or service account)
- Install rpaframework-google package
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.
Methods when using service account:
- Method 1 as environment variables,
GOOGLE_APPLICATION_CREDENTIALS
with path to service account file. - Method 2 as keyword parameter to
Init Storage
for example. - Method 3 as Robocorp vault secret. The vault name and secret key name needs to be given in library init
or with keyword
Set Robocorp Vault
. Secret value should contain JSON file contents.
Method 1. service account using environment variable
Method 2. service account with keyword parameter
Method 3. setting Robocorp Vault in the library init
Method 3. setting Robocorp Vault with keyword
Methods when using OAuth token:
- Method 1 as keyword parameter
token_file
toInit Storage
for example. - Method 2 as Robocorp vault secret. The vault name and secret key name needs to be given in library init
or with keyword
Set Robocorp Vault
. Secret value should contain JSON file contents.
Method 1. The Google Apps Script and Google Drive services are authenticated using this method.
Method 2. setting Robocorp Vault in the library init
Creating and using OAuth token file
The token file can be created using credentials.json by running command:
rpa-google-oauth --credentials <filepath> --service drive
or
rpa-google-oauth --credentials <filepath> --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
.
Example Vault content.
Using the Vault.
Installation
This library, RPA.Cloud.Google
is available via rpaframework-google package.
Check the latest package version from PyPI.
Examples
Robot Framework
Python
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
method add_drive_share
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.READER - share_type β see
DriveType
enum for possible values, defaults to DriveType.USER - notification β 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β
method add_library_components
method analyze_sentiment
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
method annotate_image
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
method annotate_video
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
method classify_text
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
method clear_sheet_values
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
Robot Framework
method copy_sheet
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
Robot Framework
method copy_spreadsheet
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
Robot Framework
method create_drive_directory
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
method create_sheet
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
Robot Framework
method create_spreadsheet
Create empty sheet with a title
- Parameters: title β name as string
- Returns: created spreadsheet_id
Examples
Python
Robot Framework
method create_storage_bucket
Create Google Cloud Storage bucket
- Parameters: bucket_name β name as string
- Returns: bucket
Examples
Robot Framework
method delete_drive_file
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
method delete_sheet
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
Robot Framework
method delete_storage_bucket
Delete Google Cloud Storage bucket
Bucket needs to be empty before it can be deleted.
- Parameters: bucket_name β name as string
Examples
Robot Framework
method delete_storage_files
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
method detect_document
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
method detect_labels
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
method detect_text
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
method download_drive_files
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
method download_storage_files
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
method export_drive_file
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
method face_detection
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
method generic_spreadsheet_batch_update
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
Robot Framework
method get_all_sheet_values
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
Robot Framework
method get_document_entities
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
method get_document_languages
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
method get_drive_file_by_id
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
method get_drive_folder_id
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
method get_keyword_arguments
method get_keyword_documentation
method get_keyword_names
method get_keyword_source
method get_keyword_tags
method get_keyword_types
method get_sheet_values
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
Robot Framework
method get_spreadsheet_basic_information
Get title, id, url and sheets information from the spreadsheet.
- Parameters: spreadsheet_id β ID of the spreadsheet
- Returns: operation result as an dictionary
method get_spreadsheet_details
Returns spreadsheet information as a dictionary.
- Parameters: spreadsheet_id β ID of the spreadsheet
- Returns: operation result as an dictionary
method get_storage_bucket
Get Google Cloud Storage bucket
- Parameters: bucket_name β name as string
- Returns: bucket
Examples
Robot Framework
method init_apps_script
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
method init_document_ai
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:
Python example:
method init_drive
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
method init_gmail
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
method init_natural_language
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
method init_sheets
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
method init_speech_to_text
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
method init_storage
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
method init_text_to_speech
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
method init_translation
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
method init_video_intelligence
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
method init_vision
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
method insert_sheet_values
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
Robot Framework
method list_messages
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
method list_processors
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:
Python example:
method list_shared_drive_files
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
method list_storage_buckets
List Google Cloud Storage buckets
- Returns: list of buckets
Examples
Robot Framework
method list_storage_files
List files in the bucket
- Parameters: bucket_name β name as string
- Returns: list of object names in the bucket
Examples
Robot Framework
method list_supported_voices
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
method load_document_response
Loads the binary object saved by Save Document Response
into
documentai.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:
Python example:
method move_drive_file
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
method process_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:
Python example:
method recognize_text_from_audio
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
method remove_all_drive_shares
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
method remove_drive_share_by_criteria
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
method remove_drive_share_by_permission_id
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
method rename_sheet
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
Robot Framework
method run_keyword
method run_script
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
method save_document_response
Save Process Document
response into a binary file.
Parameters
- document β response document object
- filepath β target file to save binary object into
Robot Framework example:
Python example:
method search_drive_files
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
method send_message
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
method set_robocorp_vault
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
method synthesize_speech
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
method to_column_letter
Convert a column number into a column letter(s).
- Parameters: number β column number to convert
- Returns: column letter(s)
method translate
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
method update_drive_file
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
method update_sheet_values
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
Robot Framework
method upload_drive_file
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
method upload_storage_file
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
method upload_storage_files
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