UiPath Activities

The UiPath Activities Guide

Invoking a Python Script

To exemplify how to use this activity pack, we have built an automation process to invoke a Python script which defines two operations, Add and Subtract. One of the methods, Add, is then called from the script and given a list of integer variables as input parameters. The result, stored in a proprietary PythonObject variable, is then converted into a .NET datatype to be further used in Studio.



The Python version you want to use has to be installed on the machine you want to run the process on.

This is how the demo can be built:

  1. Open Studio and start a new Process.
  2. Drag a Python Scope activity to the Workflow Designer.
  3. Specify the installation directory of Python in the Path property of the Python Scope activity. By default, the location is %LOCALAPPDATA%\Programs\Python\PythonXX\python.exe, where XX is the Python version you are using.
  4. Drag a Load Python Script activity in the Do section of the Python Scope and add the file path to the Python script in the File property.
  5. Create a new PythonObject variable, called MathFunctions and add it into the Result property field.
  6. Add an Invoke Python Method activity and configure its properties as follows:
    • Input Parameters - {2,3}
    • Instance - Add the variable created at step 5, MathFunctions, to this field.
    • Name - Add the name of the method inside the script you want to use, in this case add.
    • Result - Create a new PythonObject variable, called SumResultPython, and add it to this property field.
  7. Next, drag a Get Python Object activity to the workflow. Configure its properties as follows:
    • Python Object - Add the SumResultPython variable to this field.
    • TypeArgument - Select Int32 from the drop-down list.
    • Result - Create a new Int32 variable, called Result and add it to this field.
  8. Add a Message Box activity at the end of the project and configure it to display the Result variable.
    Your project should look like this:
  1. Run the process. The Message Box displays the result of the Add method.


Download example

Updated 8 months ago

Invoking a Python Script

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.