Running UiPath Processes with Python

What will you learn?

In this tutorial, you will discover how to seamlessly trigger UiPath processes using Python. By integrating Python scripts with UiPath workflows, you can harness the power of automation across various platforms. This guide will equip you with the knowledge to efficiently combine these two tools, enabling you to automate tasks effectively.

Introduction to Problem and Solution

UiPath is a renowned Robotic Process Automation (RPA) tool that simplifies the creation of automated processes visually, eliminating the need for extensive coding. However, there are instances where integrating UiPath workflows with external scripts or applications developed in languages like Python becomes necessary. Whether it involves executing an RPA process post data analysis in Python or controlling UiPath workflows based on dynamic script evaluations, merging these tools unlocks a plethora of possibilities. This tutorial delves into setting up this integration methodically, allowing for seamless communication between Python and UiPath.

Short Intro

By mastering the art of calling and executing UiPath processes directly from Python scripts, you expand your automation capabilities significantly. This fusion leverages the intuitive visual process design of UiPath alongside the vast library support provided by Python.

Code

To run a UiPath process from Python, we commonly utilize the subprocess module which enables us to spawn new processes and interact with their input/output/error streams:

import subprocess

# Replace 'path_to_your_uipath_project' with your actual project path
uipath_project_path = "C:\\path_to_your_uipath_project\\project.json"
# The UI Robot executable path may vary; adjust accordingly.
uirobot_path = "C:\\Program Files (x86)\\UiPath\\Studio\\UiRobot.exe"

# Command construction
command = f'"{uirobot_path}" execute --file "{uipath_project_path}"'

# Running UI Path process
process = subprocess.run(command)

if process.returncode == 0:
    print("Process executed successfully")
else:
    print("An error occurred while running the process")

# Copyright PHD

Explanation

In this solution:

  • Importing Necessary Module: The subprocess module is imported to facilitate interaction with system-level commands.
  • Specifying Paths: Paths for both the project.json file within your chosen UiPath project directory and UiRobot.exe are specified.
  • Constructing Command: A command string is created using these paths, instructing UiRobot.exe to execute our designated project.
  • Executing Process: The constructed command is passed into subprocess.run(), initiating your UiPath process within Python.

This approach leverages direct execution via CLI (Command Line Interface) through UiRobot.exe, ensuring efficient execution upon accurate path specifications.

    1. How do I find the exact path to ‘UiRobot.exe’? You can locate ‘UiRobot.exe’ by searching in your Program Files directory where UiPath is installed or checking environment variables if its path has been added there.

    2. Can I pass arguments/parameters from my Python script to my UiPath workflow? Yes! You can adjust the command line argument structure accordingly � refer to official documentation on �Passing Arguments� in UIRobot CLI commands.

    3. Is it necessary to have UiRobot installed separately? Generally yes, as ‘UiRobot’ is usually included in standard installations; ensure it’s accessible via CLI.

    4. Do I need admin privileges? Admin rights may be required for executing certain commands depending on system security settings or specific actions intended within UiPath processes.

    5. Can this method initiate Orchestrator Jobs too? While direct initiation isn’t possible, incorporating API calls towards Orchestrator endpoints allows for triggering jobs from Python scripts.

Conclusion

The integration of Python with UiPath presents a sophisticated solution that combines intricate scripting capabilities with robust RPA functionalities offered by UiPath. By meticulously following the outlined steps and ensuring accurate referencing of paths, one can unlock vast potential for automating tasks seamlessly across diverse technological stacks.

Leave a Comment