[RPA]: Using The Python Activity in UiPath

Level of Difficulty: Beginner.

This post will assist in using the Python Activity in UiPath which allows Python scripts to be invoked and executed from UiPath. Not only can you execute Python scripts, but you can also pass parameters through to the Python method and assign the result to a UiPath variable which can be used later in the RPA process.

Please Note: The Python Scope only supports Python versions 3.6 or earlier

What are the steps?

The steps that we will be following are:

  1. Create Python Script
  2. Install the UiPath.Python.Activities library
  3. Add a “Python Scope” Activity
    1. Point the Python Scope to the Python Interpreter through the path property
    2. Ensure that the version and target properties are correctly configured
  4. Add a “Load Python Script” Activity
    1. Add the file path to the Python script
    2. Create and assign the result variable to the result property of the activity
  5. Add an “Invoke Python Method” Activity
    1. Assign the input parameters
    2. Assign the instance name
    3. Assign the method name
    4. Create and assign the result variable to the result property of the activity
  6. Add a “Get Python Object” Activity
    1. Assign Python Object to the Invoke Python Method result variable
    2. Assign the TypeArgument to the Python method return type
    3. Create and assign the result variable to the result property of the activity
  7. Add a Message Box that displays the Python result

Deep Dive

Let’s dive deeper into the steps listed above.

Create Python Script

Before creating a new UiPath Process, a test Python Script (named BasicMath.py) should first be created (it is advised that the Python Script and the virtual environment exists in the same root folder as the UiPath Process):

# takes a list of numbers as a parameter
def addition(numbers):

    sum = 0

    for number in numbers:

        sum += number

    return sum

# takes a list of numbers and the total to be subtracted from as a parameter
def subtraction(numbers, total):

    for number in numbers:

        total -= number

    return total

# takes the state (add or subtract), list of numbers and the total to be subtracted from (if state supports it) as a parameter
def main(state, numbers, total):

    if state == "subtract":

        return subtraction(numbers, total)

    elif state == "add":

        return addition(numbers)

Install the UiPath.Python.Activities library

Create a new UiPath Process, add a sequence to the Main.xaml file and click “Manage Packages” as seen below:

Ensure that you are focused on “All Packages” when searching for UiPath.Python.Activities:

Select the UiPath.Python.Activities library and click on the Install button. After clicking the install button, click on Save and Accept when prompted:

Now that we have the library installed, we can wire our process up to Python.

Add a “Python Scope” Activity

Search for “python” in the Activities panel and drag the “Python Scope” over into the Sequence sitting in the Main.xaml file.

Now… To link the scope to the interpreter, you’ll need to provide the path to the interpreter in the “path” property of the Python Scope:

To find the path of your default Python interpreter, create a basic Python script and run the following commands:

import os
import sys

This can also be done through the command prompt:

Ensure that your target and version are correctly configured in the properties of the Python Scope:

Add a “Load Python Script” Activity

Time to grab a “Load Python Script” activity from the activities pane and drag it into the Python Scope:

Add the path to the Python Script in the “File” property of the activity:

Click on the “Result” property and hit Ctrl+K to create a new variable (of PythonObject type) named basicMathScript

Drag the “Invoke Python Method” activity over into the Python Scope:

Create a variable named inputNumberList (of type Array of [T] where T is int32) and assign the default value to {1,2,3,4,5}:

Assign the following values to the corresponding “Invoke Python Method” property:
Input Parameters: {“add”, inputNumberList, 0} (state, numbers, total)
Instance: basicMathScript (which is the result variable of the Load Python Script Activity)
Name: “main” (which is the name of the method that should be executed)
Result: hit Ctrl + k to create a variable (of type PythonObject) named pythonInvokeResult

Add a “Get Python Object” Activity

Drag the “Get Python Object” activity over into the Python Scope:

Assign the following values to the corresponding “Get Python Object” property:
Python Object: pythonInvokeResult (which is the “Invoke Python Method result)
TypeArgument: Int32 (This refers to the result type returned by the Python Method)
Result: hit Ctrl + k to create a variable (of type Int32) named pythonMainResult

Add a Message Box that displays the Python result

Search for the Message Box activity and drag it over into the Python Scope:

Assign the Text property of the Message Box to pythonMainResult.ToString

Upon execution, you should see the following Message Box appear with the result:

To test the subtraction method, feel free to play around with the parameters that are sent into the “Invoke Python Method” activity:

The final process should look like this:

The above solution is available on Github

If you have any questions, issues or feedback, drop a comment below or reach out to jacqui.jm77@gmail.com

Who is The JPanda

“This is fine.”

– Wise People Across The World

How Did The JPanda Come About?

While working at CSIR, Jacqui was exposed to using the Pandas Python library extensively. Through this, her love for Pandas and Python alike, grew – thus earning her the nickname The Panda. This nickname followed her into Britehouse where her colleagues continued to refer to her as the person who, not only knew Python extensively, but also loved to “Put it in a Panda”.


North-West University (Vaal Triangle Campus)

Undergraduate Degree: Bachelor of Science in Information Technology (IT)

Module Summary:
Accounting, Business Management, Philosophy, C#, Java, Data Structures, Systems Analysis and Design, Operating Systems, Decision Support Systems, Artificial Intelligence, Databases, Mathematics, Discrete Mathematics, Statistics and Expert Systems.

Honors Degree: Bachelor of Science in Computer Science and IT with Information Systems (2018)

Module Summary:
Artificial Intelligence, Computer Security, Decision Support Systems and Information System Engineering.


UiPath Certifications

The following certifications were issued by UiPath:

  • RPA Starter Training (Oct 2019)
  • Business Analyst Training (Oct 2019)
  • Level 1 – Foundation Training – 2018.3 (Oct 2019)
  • AI Computer Vision 2.0 (Oct 2019)
  • RPA Developer – SAP Automation Training (Oct 2019)
  • UiPath Licensing Training (Oct 2019)
  • UiPath Security Training (Oct 2019)
  • Level 2 – Orchestrator 2018.3 Training (Nov 2019)
  • RPA Developer Advanced (Nov 2019)

SAFe Certifications

The following certification was issued by Scaled Agile:

  • Certified SAFe® 4 Agilist (Jan 2019)

Past Experience

North West University (Feb 2016 – Nov 2016)

Lecturer’s Assistant, Supplemental Instruction (SI) Leader and Facilitator

While doing her BSc in IT at North West University Vaal Triangle Campus, Jacqui worked as a student assistant, facilitator and supplemental instruction (SI) leader.

Duties included:

  • Attending classes and assisting students during practicals
  • Setting up and conducting facilitation sessions with students who needed extra assistance
  • Setting up and conduction supplemental instruction sessions (extra classes) with students

Falatame Trading and Projects – Pty Ltd (Oct 2016 – Jan 2017)

Social Media Manager and Information Technology Consultant

Jacqui did freelance social media management and IT consulting while doing her undergraduate degree.

Duties included:
– Creating social media accounts
– Creating the organisational website
– Managing the content shared on social media accounts
– Advising on social media marketing strategies
– Consulting on IT related scenarios

Council for Scientific and Industrial Research (CSIR)
(June 2017 – July 2017; Nov 2017 – Feb 2018)

Data Scientist and Data Engineer (DSIDE Program)

Jacqui used the university breaks, while doing her 3rd year of her undergrad, to work for the CSIR in their DSIDE program.

Duties included:

  • Data collection
  • Data wrangling (using Python)
  • Data analysis and visualisation (using Python)
  • Ontology engineering

Young Innovations

Freelance Graphic Designer (Aug 2016 – Dec 2017)

While Jacqui did her undergrad, she also spent a period of time freelancing as a graphic designer.

Duties included:

  • Designing event pamphlets and posters
  • Designing logos
  • Social media management and marketing

Britehouse: A Division of Dimension Data

Junior Software Developer (Feb 2018 – Sep 2018)

After working at CSIR, Jacqui was employed as a web developer at Britehouse.

Duties included:

  • Support and maintain various websites (SharePoint with C# integration)
  • Support and maintain an existing chatbot solution (C# with bot framework and LUIS integration)
  • Create websites (ASP.NET MVC)

Junior Business Intelligence (BI) Developer (Sep 2018 – Mar 2019)

Jacqui then became familiar with the world of business intelligence, in which she took a keen interest, before moving over to the Data Services department where she continued her career as a BI developer.

Duties include:

  • Creating SQL Server databases, tables, views and stored procedures
  • Creating SSIS solutions
  • Creating SSAS solutions (including DAX and MDX key measures)
  • Creating Power BI reports (including Power Query key measures)
  • Maintaining a business intelligence environment
  • Maintaining and supporting data solutions
  • Mentor grads

Intermediate Data Engineer (Apr 2019 – Nov 2019)

Jacqui was put forward for a promotion and due to the position of the organisation and Jacqui’s skill set, it was decided to promote her into a data engineering position.

Duties included:

  • Creating Python Scripts for basic tasks (MS Teams notifications, slack notifications, MS Graph querying, text extraction and manipulation, and more)
  • Creating data capturing solutions (Using Power Apps and ASP.NET Core MVC Web Apps)
  • Creating data ingestion APIs (Using ASP.NET Core MVC Web APIs and Swagger)
  • Data extraction (Using SOAP and REST API calls through Python and C#)
  • Introducing automation into existing processes (Using SQL, MS Flow, Azure Stack, Python and UiPath)
  • Replatforming an IBM based real-time analytics platform solution using the following tech:
    • Apache Nifi (with MQTT)
    • Apache Beam
    • Reddis
    • Python
    • Docker
    • MongoDB
    • SQL Server
    • Prometheus and Grafana
    • Git

Dimension Data

Automation Architect (Dec 2019 – Present)

Jacqui then moved up into the internal IT Services department within Dimension Data as an automation architect.

Duties include:

  • Architecting automation solutions (mostly RPA using UiPath or Python)
  • Developing automation solutions
  • Advising on client facing automation solutions, where necessary
  • Mentoring and assisting colleagues