Python Automation in UiPath Using RCC

UiPath is one of the most powerful automation platforms out there. Using UiPath Studio, developers have access to thousands of NuGet packages that they can use to automate almost any process. But no automation platform is perfect, and some automation scenarios require other software and programming languages.

For example, if a UiPath automation requires a lot of web crawling and scraping, it would benefit from invoking Node.js and using Crawlee rather than using UiPath's UI automation activities. Or if a UiPath automation requires the use of AI, ML, or NLP, it would benefit from using Python, since Python is one of the first languages people think of when they think of AI / ML / NLP.

I will confess that earlier in my automation career, I was firmly against using any other languages beside .NET in my UiPath solutions. My reason for this was that the one drawback to using other tools is the major overhead cost of managing bot VMs and Python installations.

Managing Python Installations

Suppose a UiPath automation uses a Python script that runs on Python 3.8.15, and this project uses an NLP package (NLTK, 3.6). To run this bot in test and production VMs, someone needs to install Python 3.8.15 on every VM, and install NLTK using pip. This may not seem so bad at first, but suppose a bug occurs later on, and the solution is updating NLTK to 3.7. Now someone has to go through each VMs again, updating NTLK to 3.7. Maybe someone else might build a UiPath automation that requires Python 3.10.6. If this happens, each VM would need to have two versions of Python installed.

If Python installation isn't planned carefully, then juggling different versions of Python and its packages can get out of control very quickly. And even if things are planned perfectly, it still takes time to manage Python installations manually.

Solutions

Thankfully there are ways to manage Python installations efficiently. The UiPath Marketplace has a package that allows you to create a Python virtual environment (venv), where packages are loaded and code is executed. The venv is then deleted once the Python code finishes.

This package addresses the issue of conflicting versions of the same packages, but managing multiple Python installations is still an issue. Additionally, some Python packages are better installed from conda rather than pip, and the UiPath package above does not support conda installation. But there is a solution that manages all of this effortlessly, and it's open-source and free to use.

Robocorp and RCC

If you've seen other articles on this site you'll know that I love Robocorp. For those who haven't heard of Robocorp before, they're an RPA company that in some ways can be seen as a UiPath competitor, but in other ways is forging its own identity as an RPA vendor.

Among Robocorp's product offerings, their command-line tool RCC is the focus of this article. To borrow Robocorp's description:

RCC is a set of tooling that allows you to create, manage, and distribute Python-based self-contained automation packages

We can use this tool in UiPath projects to run Robocorp projects, and it will handle all the Python and package installations automatically. No manual work needed!

Create a Robocorp project and ensure it follows the right robot structure. Store the Robocorp project inside your UiPath project. Then in your UiPath project, add this code to download RCC and execute your Robocorp project:

' In this example, the Robocorp project folder, named "PythonSteps",
' is stored in the root of the UiPath project folder
Dim rccDirectory As String = Directory.GetCurrentDirectory + "\PythonSteps"

Dim rccUrl As String = "https://downloads.robocorp.com/rcc/releases/latest/windows64/rcc.exe"

' This command navigates to the Robocorp project folder,
' downloads RCC, and runs the Robocorp project
Dim rccCommand As String = "/c cd " + startDirectory + " & curl -o rcc.exe " + rccUrl + " & rcc run"

' Start the Robocorp project and wait for it to finish
' before UiPath continues the rest of its steps
Process.Start(New ProcessStartInfo("cmd", rccCommand)).WaitForExit

This code snippet is just the beginning of what RCC is capable of, and this snippet can be enhanced or modified depending on the automation's requirements:

  • Have UiPath throw an error if the Robocorp project doesn't complete in a certain amount of time
  • Pass arguments from UiPath to the Robocorp project using the command line (or some other way)