How can we help?

Search for answers or browse our knowledge base

< All Topics
Print

Automation via Python API

Introduction

Install python >=3.7

Install virtualenv

pip install virtualenv

Create a development folder

mkdir /path/to/dev/folder
cd /path/to/dev/folder

Create a virtual environment
Virtual environments allow you to have isolated space on your computer for Python projects, ensuring that each of your projects can have its own set of dependencies that won’t disrupt any of your other projects.

virtualenv venv_name

Activate the virtual env

. .\path\to\dev\folder\venv_name\Script\activate

You may need to authorize Script execution, open powershell as admin

Set-ExecutionPolicy RemoteSigned
...
>> O

Deactivate the virtual env

deactivate
To install Gt_Automation simply run:
pip install gt_automation_x.x.x.whl

Connexion informations

Connection information is passed via a ConnectionInfo object which contains the following fields:

Parameters

  • host (str) – server name or ip adress.
  • port (int) – instance or http server port.
  • gt_login (str) – name of the user connecting to the instance
  • gt_password (str) – user password.
  • tcp (bool, optional) – communication method: True for tcp, False for http, default is False.
  • ssl (bool, optional) – use ssl for tcp connection default is False
  • alias (str, optional) – instance name only for http.
  • **kwargs (optional) – optional argument for http see requests package documentation, do not use ‘param’ and ‘data’.

Examples :

Here we will see some simple usage of the package.

For the first example, we will create an interface using TCP communication:

from gt_automation import GtConnectionInfo

IP = '192.168.240.26'
PORT = 3000
GTLOGIN = 'username'
GTPASSWORD = 'password'

cmd = GtConnectionInfo(IP, PORT, GTLOGIN, GTPASSWORD,tcp=True)

It is also possible to use HTTP to communicate with the server:

from gt_automation import GtConnectionInfo

IP = '192.168.240.27'
PORT = 80
GTLOGIN = 'username'
GTPASSWORD = 'password'
ALIAS = 'Math'

cmd = GtConnectionInfo(IP, PORT, GTLOGIN, GTPASSWORD, ALIAS, tcp=False)

Note that in this example we have added an other argument alias, this argument is used to specify the target instance name. When using the TCP communication, its the connection port that fulfill this role.

Action classes

Launch Collection Action : action_campaign_launch

action_campaign_launch(namemsgstatement_date=Noneglobal_redirect_address=''user_cypher=Falsewait_terminated=Falsetimeout=0)

Execute campaign launch action.

Parameters:
  • name (str) – action name
  • msg (GtMessage) – message to send
  • statement_date (date) – statement date of the campaign
  • global_redirect_address (str, optional) –

Integration action : action_campaign_integration

action_campaign_integration(namestatement_datewait_terminated=Falsetimeout=0)

Execute integration action.

Parameters:
  • name (str) – action name
  • statement_date (date) – statement date of the campaign
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns:
          GtActionResult
Raises:
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side

Action for launching the report : action_reporting

action_reporting(namemsgglobal_redirect_address=''wait_terminated=Falsetimeout=0)

Execute reporting action.

Parameters
  • name (str) – action name
  • msg (GtMessage) – message to send
  • global_redirect_address (str, optional) –
1) Action for launching the report of the questionnaire : action_reporting_qst
action_reporting_qst(namemsgstatement_dateglobal_redirect_address=''wait_terminated=Falsetimeout=0)

Execute the survey reporting action.

Parameters
  • name (str) – action name
  • msg (GetMessage) – message to send
  • statement_date (date) – statement date of the campaign
  • global_redirect_address (str, optional) –
2) Action for launching the report of the campaign : action_reporting_launch
action_restitution_launch(namemsgstatement_date=Noneglobal_redirect_address=''user_cypher=Falsewait_terminated=Falsetimeout=0)

Execute a restitution launch action.

Parameters
  • name (str) – action name
  • msg (GetMessage) – message to send
  • statement_date (date) – statement date of the restitution
  • global_redirect_address (str, optional) –

SQL script action : action_sql

action_sql(namewait_terminated=Falsetimeout=0)

Execute an sql action.

Parameters
  • name (str) – action name
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns
GtActionResult
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side

Campaign close action : action_campaign_close

action_campaign_close(namemsgstatement_dateis_restitdefault_action_settingsattach_qstattach_histosend_messagewait_terminated=Falsetimeout=0)

Execute campaign close action.

Parameters :
  • name (str) – action name
  • msg (GtMessage) – message to send
  • statement_date (date) – statement date of the campaign
  • is_restit (bool) – the targeted campaign is a restitution
  • default_action_settings (bool) – use the default action settings
  • attach_qst (bool) – join last answer or last survey send (ignored if default_action_settings is true)
  • attach_histo (bool) – join the campaign historic (ignored if default_action_settings is true)
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns :
           GtActionResult
Raises:
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side

Re-send action : action_campaign_followup     

action_campaign_followup(model_namemsgstatement_datedefault_action_settingsattach_qstattach_histoselect_no_answersselect_pendingselect_invalidatedentities=[]wait_terminated=Falsetimeout=0)

Execute campaign Follow up action.

Parameters:
  • model_name (str) – model name
  • msg (GtMessage) – message to send
  • statement_date (date) – statement date of the campaign
  • default_action_settings (bool) – use the default action settings
  • attach_qst (bool) – join last answer or last survey send (ignored if default_action_settings is true)
  • attach_histo (bool) – join the campaign historic (ignored if default_action_settings is true)
  • select_no_answers (bool) – send reminder to not responding entities
  • select_pending (bool) – send reminder to entities waiting for validation
  • select_invalidated (bool) – send reminder to invalidate entities
  • entities (list of AnswerEntity) – list of entities to raise (default=[]), by default raise all entities
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns :
           GtActionResult
Raises:
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side

Combined action : action_combined

action_combined(namestatement_date=Nonewait_terminated=Falsetimeout=0)

Execute a combined action.

Parameters
  • name (str) – action name
  • ( (statement_date) – obj:’datetime.Date’): statement_date used

User creation action : action_create_users

action_create_users(namewait_terminated=Falsetimeout=0)

Execute a create users action.

Parameters
  • name (str) – action name
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns
GtActionResult
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side

An other example of static command were we create a new user and give him some right.

from gt_automation import GtUser, UserPrivilege

...

MODEL_NAME = 'Edit-Pays-Ville'

# Create the connection Info
cmd = GtConnectionInfo(IP, PORT, GTLOGIN, GTPASSWORD, ALIAS, False)
# create a new user
user = GtUser("test_user", "testtest", UserPrivilege.NONE)
user.must_change_pwd = True
user.add_model_group_couple(MODEL_NAME, "Valideur")
user.add_model_group_couple(MODEL_NAME, "Visualiseur")
# Insert the new user
cmd.insert_user(user)

As it was say earlier the actions command differ from the static one, they take time to finish, in many case you will want to have the final result of the action. All action command have two more arguments wait_terminated (bool) and timeout (int) express in minutes.

# start the polling action and wait maximum five minutes to get the result
poll_res = cmd.do_polling(True, 5)

Right answer removal action : action_remove_answer_rights

action_remove_answer_rights(namewait_terminated=Falsetimeout=0)

Execute a remove answer rights action.

Parameters
  • name (str) – action name
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns
GtActionResult
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side

Static classes

Message handling : get_message_from_name

get_message_from_name(model_namemsg_name)

Get the given message from the given model.

Parameters
  • model_name (str) – name of the model
  • msg_name (str) – name of the message
Returns
GtMessage
Raises
ValueError – An error occured during the creation of the command

Polling management : do_polling, is_polling et get_polling_log

1) Polling request
do_polling(wait_terminated=Falsetimeout=0)

Execute the polling command.

Note

if wait_terminated is set to False the the command will return (-1, GtPollingStatus.NONE).

Parameters
  • wait_terminated (bool, optional) – session id returned by the logon command (default = False).
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns
a tuple containing the polling id and the polling status.

Return type

(int, GtPollingStatus)
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side

2) Polling in progress

is_polling()

Check if a polling command is running.

Returns
True if a polling command is running.
Return type
bool
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side

3) Polling log

get_polling_log(poll_id)

Retreive the logs of the given polling.

Parameters
poll_id (int) – polling id
Returns
string containing the logs.
Return type
str
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side

Action management : get_action_log et get_action_status

1) get_action_log
get_action_log(action_id)

Retreive the logs of the given action.

Parameters
action_id (int) – action id
Returns
string containing the logs.
Return type
str
ValueError – An error occured during the creation of the command
2) get_action_status
get_action_status

Return the status of the given action.

Parameters
answer_id (int) – id of the answer to retreive.
Returns
GtActionResult
Raises
ValueError – An error occured during the creation of the command

Campaign management : delete_campaign et list_campaign

1) Deleting a campaign : delete_campaign 
delete_campaign(model_namestatement_dateis_restitdelete_histo)

delete the given campaign.

Parameters
  • model_name (str) – name of the model
  • statement_date (date) – statement date of the campaign
  • is_restit (bool) – the targeted campaign is a restitution
  • delete_histo (bool) – delete the campaign historic
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
2) list of campaigns : list_campaign
list_campaign()

Retreive the campaign list of the instance.

Returns
List of GtCampaign
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side

Response and Questionnaire Management

action_open_close_qst(namestatement_date=Nonewait_terminated=Falsetimeout=0)

Execute an open close qst action.

Parameters
  • name (str) – action name
  • statement_date (date) – statement date of the restitution
  • wait_terminated (bool, optional) – wait for the end of the action execution
  • timeout (int, optional) – timeout in minute if wait_terminated is True.
Returns
GtActionResult
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
  • GtActionExeption – An error occured during the action processing client or server side
1) Last response date : last_answer_date_for_campaign
last_answer_date_for_campaign(model_namestatement_date)

Get the date of the most recent answer for the given campaign.

Parameters
  • model_name (str) – name of the model
  • statement_date (date) – statement date of the campaign
Returns
date
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
2) List of responses : list_answer
list_answer(model_namestatement_date)

List the answer for the given campaign.

Parameters
  • model_name (str) – name of the model
  • statement_date (date) – statement date of the campaign
Returns
list of AnswerEntities
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
3) Getting the Questionnaire from an Answer : get_answer
get_answer(dst_fileanswer_ideditable=False)

Save the the given answer to the destination file.

Parameters
  • dst_file (str) – Path to the file were the qstx will be saved.
  • answer_id (int) – id of the answer to retreive.
  • editable (boll, optional) – if True the qstx will be editable else it will be a preview.
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
4) Getting a Sent Questionnaire : get_qst_sent
get_qst_sent(dst_fileqst_ideditable=False)

Save the the given survey to the destination file.

Parameters
  • dst_file (str) – Path to the file were the qstx will be saved.
  • qst_id (int) – id of the answer to retreive.
  • editable (bool, optional) – if True the qstx will be editable else it will be a preview.
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
5) Closing a questionnair : close_qst
close_qst(qst_idpast_and_future=False)

Close the given survey.

Parameters
  • qst_id (int) – id of the survey to close.
  • past_and_future (bool) – if true refuse all futur answer else refuse all answers including past one.
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
6) Deleting a response : delete_anwser
delete_answer(answer_id)

Delete the given answer.

Parameters
answer_id (int) – id of the answer to retreive.
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side

Managing models

list_model() 

Managing  projects

list_project() 

User management

1) Creation of new users and assignment of rights for these new user
insert_user(user)

Add a new user to the instance.

Parameters
user (GtUser) – user to add
Raises
ValueError – An error occured during the creation of the command
2) List of users
list_user()

Retreive the user list of the instance.

Returns
list of GtUser
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
3) Editing users
edit_user(user)

Edit an user, the user id need to be fill in.

Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
4) Deleting users
delete_user(id)

Edit an user, the user id need to be fill in.

Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side

Connexion with the server

1) Establish connection with the server
logon()

Establish connection with the server.

Note

The logon command is include in other command.

Returns
session id of the connection.
Return type
str
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
2) Disestablish connection with the server
logout(sessionId)

Establish connection with the server.

Note

The logon command is include in other command.

Parameters
sessionId (str) – session id returned by the logon command.
Returns
True if the deconnection succed.
Return type
bool
Raises
  • ValueError – An error occured during the creation of the command or the parsing of the answer
  • GtCommandExeption – An error occured during the processing of the command client side
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Previous Automation via PowerShell API
Table of Contents