Python Integration With UiPath

Python Integration With UiPath

Python language needs no introduction today and with the growing no of machine learning & artificial intelligence use cases in RPA industry its is obvious choice to integrate your workflow with python.

Due to huge no of the libraries(modules and packages) available in python its first choice of language to perform such task…One such example is Pandas – an amazing library which provides flexible and high-performance data structure manipulation and analysis tools.

Not this …there are many such libraries which provide a super quick way to perform your task such as Flask, NumPy, TensorFlow, Skit-learn etc.

Integration of cognitive use cases becomes easy with the python due to such machine learning, Computer vision, Artificial intelligence modules and thousand of examples available to support your idea.

Last week, I was working with OCR tools to integrate with uipath and then based on the result we were getting from the image… we decided to process the IMAGE using Computer Vision for Preprocessing & then tesseract to read data contained in the pdf.

After some initial hiccups of setting Python Interpreter correctly, we were able to perform the task easily.

So I have documents the steps required for Integration of Python … I hope this will help you…

Pre-Requisite

  1. Supported Python Interpreter (Not all Interpreter are being supported by UiPath at the moment such as 3.7 or 3.7 +)
  2. UiPath Python Activities Pack Must be added as Dependencies
  3. Notepad ++ / Pycharm (Or any Python Editor )- Optional to test script outside Uipath

How to Enable UiPath Python Activities Pack

To work with python activities you need to first add UiPath Python Activities Pack as dependencies in your project.

You can enable and install same from Manage Packages Window as shown below.

Python Integration With UiPath 1
Select UiPath Python Activities Pack and click on install to add required dependency .

Once that is enabled …you will be able to see different activities of python from search panel as below to test if they are successfully added.

Python Integration With UiPath 2

So far so good…Lets move to steps required for integrating the Python inside Uipath Workflow.

The UiPath.Python.Activities contain the following activities:

  • Get Python Object – Retrieves the .NET type used in a specified Python script.
  • Python Scope – A container which provides scope for Python activities.
  • Invoke Python Method – Helps you run a specified method from a Python script directly in a workflow.
  • Load Python Script – Converts your Python code to a PythonObject variable.
  • Run Python Script – Enables you to execute Python code. You can input the code directly in the activity or provide a file path for it.

Read More at Uipath Documentation – https://docs.uipath.com/releasenotes/docs/uipath-python-activities

For this example, we are going to write a small python program which will calculate the sum of first N(Numbers Passed as Argument) and display result in the output window. Let’s say python program is saved as “test.py”

# Return the sum of square of first n natural numbers
def squaresum(n):
    sm = 0
    for i in range(1, n + 1):
        sm = sm + (i * i)
    return sm

Our final work flow will look like this….

Python Integration With UiPath 3

STEP 1- Drag Python Scope into your workflow window and set the following properties.

  • Python Path – This should be the location where your Python interpreter is installed, You should give the path at the Directory level. For my example its – C:\Users\XXXX\AppData\Local\Programs\Python\Python36 (Make sure to change accordingly)
  • Target – Did you install 64-bit variant or 32-bit variant of Python (In my case its x64)
  • Version – This is important as not all the python variants can be integrated with the Uipath so you should go with the available list only for example you won’t find python 3.7 + as of now
python scope activity with uipath
python scope activity with uipath

STEP 2 – Load Python Script

  • In this step, you need to either enter code in properties panel if small block or you should load external python file here(for my example its test.py kept inside data folder)
  • You need to create a python Object as Result output which will be used for further processing(In my example I have created variable of python object type as sumsquare ), You can give any name

STEP 3- Invoke Python Method

This is the most important step in python integration part –

  • Input Argument – You need to pass the argument to your python method here, So you need to make sure that arguments are matched with the program you have written. As of now, there is no support for named tuple and you need to provide your inputs as a dictionary as {arg1, arg2}. For my example, the input is {Number} as I have created Number variable to pass as Input Argument
  • Instance – You also need to recall your Python Instance Variable which you created in the previous step to be passed here. This is useful in case you need to invoke multiple python scripts so that the required instance of the object is referred. For my example python object is sumsquare
  • Name – Name is Name of the method inside your python’ program which needs to be called. Make sure to pass them inside ” ” as this is String – Name of the method to be invoked
  • Output – You need to store the result of the executed method into some python object which can be used for further processing. For my example, we have created a variable as SumPythonObject to store the result.
Python Integration With UiPath 4

STEP 4 – Get Python Object

In this step the result variable we have created in the previous step need to be converted into .NET type object so that they can be used into Uipath , Here we simple provide name of Variable we wish to convert into and Type of object.

PS- Some time you need to be careful here as all type of python objects cant be converted into .NET objects, You need to make sure types are compatible.

Once .NET object Variable is ready you can use with as usual to work in Uipath. For my example, SumUipathObject is the variable name which is converted from SumPythonObject variable.

Some Common Issues you might face when you integrate Python with Uipath

  • UiPath Python Host32 has stopped working- Unfortunately, the best I can say is to re-re-check your environment, as I believe the correct Anaconda installation or Python interpreter is NOT being referenced. which causes this issue. Also at the moment, no support is available for Python 3.7 + so you need to ensure that you are using supported python variant.
  • UiPath Robot has stopped working – You also might face UiPath Robot has stopped working, It may be due to any reason and hence it requires multiple steps to ensure you are nothing wrong with environment setup, So Run DiagTool using below step and go through the logs to see what went wrong –
    • Open the UiPath Robot installation folder: %localappdata%\UiPath\app-18.1.3
    • Open a Powershell or CommandPrompt window
    • .\UiPath.DiagTool.exe -f crash_report.zip
    • Then you can find the report file on your desktop.

Please feel free to reach me incase you are still facing any issues with your python integration with Uipath.

Happy Automation !

2 thoughts on “Python Integration With UiPath”

  1. How we can Covert RPA code written using UiPath to python.
    Mainly how we can develop an RPA using python .
    Please guide.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top