Package: anymate
In order to use this library, you need to have an Anymate account. Please visitanymate.iofor more information.Anymate Python SDK is written in Python 3.
The SDK is available as open source and can be found onour github page.
You can find the documentation for the SDK as part of theAnymate Developer docs.We have also published it atpypi.org. Installing the Anymate package is done with the following command:#Install through pippipinstall--upgradeanymateOnce installed, you just need to import anymate in your python program and you are ready to goimportanymateAfter anymate has been imported, you have to initialize the client to communicate with Anymate.
The functions exposed in the client mirror the endpoints available in the API. We recommend going to the individual pages to learn more.The SDK is built to automatically take care of authentication with Anymate as well as refreshing access_tokens as needed. Once the anymate.client is initialized, you don't have to worry about it.You can see an example of a simple automation based on the Allocator Pattern below, where the automation script is working in one process and creating new tasks in another.#Import the anymate libraryimportanymate#Setting up variables for future useclient_id="My client id"client_secret="My API secret"username="Mate Username"password="Mate Password"#The process where the script is workingmyProcessKey="myProcessKey"#The target Process where we want to create tasks intargetProcessKey="targetProcessKey"#Initialize the clientclient=anymate.client(client_id,client_secret,username,password)#Check if the script should start workis_ok_to_run=client.OkToRun(myProcessKey)ifnotis_ok_to_run.okToRun:#If there is nothing to do, then stop the script herereturn# Business logic not included. We assume that "new_tasks" is an array with objects ready for anymate.#Let Anymate know that work has begunrun=client.start_or_get_run(myProcessKey)fortaskinnew_tasks:#create a task for each object in the array 'new_tasks'client.create_task(targetProcessKey,task)#Let Anymate know the work is doneclient.finish_run(dict(runId=run.runId))Making a script to take Tasks from the Queue and perform work on them is equally simple.# Import the anymate libraryimportanymate# Setting up variables for future useclient_id="My client id"client_secret="My API secret"username="Mate Username"password="Mate Password"# The process where the script is workingmyProcessKey="myProcessKey"# Initialize the clientclient=anymate.client(client_id,client_secret,username,password)# Check if the script should start workis_ok_to_run=client.OkToRun(myProcessKey)ifnotis_ok_to_run.okToRun:# If there is nothing to do, then stop the script herereturn# Business logic not included. We assume that "new_tasks" is an array with objects ready for anymate.# Take first task from the queue - notice it is returned as a dictionarytask=client.take_next(myProcessKey)#Our workloop continues while the TaskId is above 0. If the queue is empty, the TaskId will be -1.whiletask['taskId']>0:#Businesslogic omitted. We have created a dummy function to take the Task as input and return if it is solved (true) or goes to manual (false)task_is_solved=PerformBusinessLogic(task)iftask_is_solved:#Task was solved - solved and manual takes both dictionaries and objects, as long as they have the right keys/attributes.solved_result=client.solved(dict(taskId=task['taskId'],reason='Solved',comment='Task was solved'))else:#Send task to Manualmanual_result=client.manual(dict(taskId=task['taskId'],reason='Manual',comment='Task was sent to Manual'))#Logic to handle exceptions and errors omittedtask=client.take_next(myProcessKey)Enterprise On-PremisesThe anymate SDK supports customers who have Anymate installed On-Premises with an Enterprise license out of the box.
In order to let anymate know you are running on a on-premises license, simply initialize the client with On Premises mode enabled.importanymate# Initialize Client as alwaysclient_id="My client id"client_secret="My API secret"username="Mate Username"password="Mate Password"client=anymate.client(client_id,client_secret,username,password)#Define a Client uri and an auth uriclient_base_uri="http://localanymateauth_base_uri="http://localanymateauth#Set On Premises modeclient.set_on_premises_mode(client_base_uri,auth_base_uri)#From here on, you can use the client as you otherwise would