Most automation companies leverage the .NET Framework as a core language, particularly in the top three RPA platforms: Blue Prism, UiPath, and Power Automate. However, Automation Anywhere uses Java, and Power Automate utilizes Azure Functions and AI-enhanced capabilities along with the .NET Framework.
RPA Platform | Main Languages | Reasons |
---|---|---|
Blue Prism |
.NET Framework(C#, VB.NET, J#) |
Enterprise compatibility, Windows-focused, Scalability, ease of use, developer-friendly |
UiPath |
.NET Framework( C# and VB.NET) |
Enterprise compatibility, Windows-focused, Scalability, ease of use, developer-friendly |
Automation Anywhere |
Java |
Platform independence( Windows, Linux, Mac OS) |
Power Automate |
.NET, JavaScript, Azure functions |
Microsoft ecosystem, serverless computing |
Each RPA company has chosen a specific programming language, initially based on the core technical requirements and ecosystems they aimed to serve. Over time, these platforms have significantly expanded their capabilities beyond their original offerings.
The integration of Python and utilizing the Python libraries are important in the age of AI, Chat GPT, and Agentic AI. Although this article focuses on integrating Python with Blue Prism, the outlined steps can also be applied by small changes with other RPA tools.
- Prerequisites:
- Blue Prism and Python should be installed (recommended version: 3.7+) on your machine.
Ways to Integrate Python in Blue Prism
Integrating Python With Blue Prism Using Dynamic Variables
Before providing a high-level overview of each method, let’s address a common requirement: integrating Python and Blue Prism when the Python script depends on variables coming dynamically from Blue Prism.
Recommended Approach
- Store the Python script in a text file: Create a text file for your Python script. This file will act as a template where placeholders will be dynamically replaced by Blue Prism variables.
- Use placeholder notation: Use placeholders like
<variable1>
,<variable2>
, etc., within your script. These placeholders will be dynamically replaced by Blue Prism during execution. - Read the text file in Blue Prism: Read this text file using Blue Prism, replace placeholders dynamically with actual variable values from Blue Prism, and execute the Python script accordingly.
Sample Python Script With Placeholders
Save the following script as a text file named SampleText.txt
. You will dynamically replace the placeholders (<variable1>
and <variable2>
) in Blue Prism:
import time
# Specify the file path and open it in write mode
file_path = r'<variable1>'
txt_file = open(file_path, '<variable2>')
# List of fruits with quantities
fruits = ["grapes-2", "banana-1", "Apple-2"]
# Write each fruit to the file with a 10-second delay
for fruit in fruits:
time.sleep(10) # Wait for 10 seconds before the next write
txt_file.write(fruit + '\n') # Write the fruit and move to the next line
# Close the file
txt_file.close()
Method 1: Execute the Python Script
Overview
In this method, we use Blue Prism’s built-in Utility-Environment: Start Process action to execute a Python script. This method does not expect any output from the script, and Blue Prism does not wait for the Python script to complete before proceeding with other steps.
Python Script Example
The following Python script writes data to a text file with a 10-second delay between each write:
import time
# Specify the file path and open it in write mode
file_path = r'C:\Users\ursha\Desktop\All\Python\output.txt'
txt_file = open(file_path, 'w')
# List of fruits with quantities
fruits = ["grapes-2", "banana-1", "Apple-2"]
# Write each fruit to the file with a 10-second delay
for fruit in fruits:
time.sleep(10) # Wait for 10 seconds before the next write
txt_file.write(fruit + '\n') # Write the fruit and move to the next line
# Close the file
txt_file.close()
Inputs
When using this method in Blue Prism’s Start Process action, the following inputs are required:
- Application: Path to the Python executable file(ending with .exe)
- Example:
C:\Path\to\python.exe
- Example:
- Arguments: Path to the actual Python script that contains the logic to execute
- Example:
C:\Users\<userName>\Desktop\All\Python\script.py
- Example:
- Use Shell:
- Set this to
False
to invoke the Python file directly using the operating system. - Set this to
True
if you want the script to execute through cmd.exe or PowerShell.
- Set this to
Outputs
Executing this method will return the following:
- Process ID: The unique identifier for the started process
- Process Name: The name of the started process, typically the name of the Python executable
Method 2: C# Integration With Python
The script is written in C# and will wait until the Python script execution completes before moving forward.
- Handles both the standard output and error stream from the executed Python script
- Boolean variables are expected:
- Output (
Bool_OP
) - Error messages (
Bool_Error
) - Run through the shell (
Bool_Shell
) - Run invisibly in the background (
Bool_ExecuteBackground
)
- Output (
- Required namespaces: This should be added in the namespaces in the initialize page.
System.Diagnostics
System.IO
andSystem.Diagnostic
were included
Inputs
You need to pass the following parameters:
PythonExecutable
: The path to the Python executable file (ending in .exe)- Example:
@"C:\Python39\python.exe"
- Example:
PythonFile
: The path to the Python script you intend to executeBool_OP
: Set this totrue
if you want to capture the script’s output.Bool_Error
: Set this totrue
if you want to capture any errors during execution.Bool_Shell
: Set this totrue
if you want to run the script through the shell.Bool_ExecuteBackground
: Set this totrue
if you want to execute the script invisibly in the background.
Outputs
O_Result
: Captures the standard output of the Python scriptO_Error
: Captures any errors produced by the Python script
// Path to Python executable
string pythonExe = @PythonExecutable;
// Path to Python script
string scriptPath = @PythonFile;
string result1 = "";
string error = "";
// Create ProcessStartInfo to configure how to run the script
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = pythonExe;
processStartInfo.Arguments = $"\"{scriptPath}\"";
//processStartInfo.Arguments = scriptPath;
processStartInfo.RedirectStandardOutput = Bool_OP; // Capture standard output
processStartInfo.RedirectStandardError = Bool_Error; // Capture errors
processStartInfo.UseShellExecute = Bool_Shell; // No shell execution
processStartInfo.CreateNoWindow = Bool_ExecuteBackground; // No visible window
// Start the process
Process process = Process.Start(processStartInfo);
if (process != null)
{
// Read the output from the process
StreamReader reader = process.StandardOutput;
result1 = reader.ReadToEnd();
// Read errors if there are any
StreamReader errorReader = process.StandardError;
error = errorReader.ReadToEnd();
// Wait for the script to finish execution
process.WaitForExit();
// Close the streams and dispose of the process
reader.Close();
errorReader.Close();
process.Close();
}
O_Result =result1;
O_Error =error;