DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Rust vs Python: Differences and Ideal Use Cases
  • Applying the Pareto Principle To Learn a New Programming Language
  • Start Coding With Google Cloud Workstations
  • Segmentation Violation and How Rust Helps Overcome It

Trending

  • Java Virtual Threads and Scaling
  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  • A Guide to Developing Large Language Models Part 1: Pretraining
  1. DZone
  2. Coding
  3. Languages
  4. Step-By-Step Guide to Integrating Python With RPA (Blue Prism)

Step-By-Step Guide to Integrating Python With RPA (Blue Prism)

Although this article focuses on integrating Python with Blue Prism, the outlined steps can also be applied by small changes with other RPA tools.

By 
Harish Mogulluri user avatar
Harish Mogulluri
·
Dec. 16, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.9K Views

Join the DZone community and get the full member experience.

Join For Free

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

  1. 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.
  2. Use placeholder notation: Use placeholders like <variable1>, <variable2>, etc., within your script. These placeholders will be dynamically replaced by Blue Prism during execution.
  3. 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:

Python
 
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:

Python
 
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:

  1. Application: Path to the Python executable file(ending with .exe)
    • Example: C:\Path\to\python.exe
  2. Arguments: Path to the actual Python script that contains the logic to execute
    • Example: C:\Users\<userName>\Desktop\All\Python\script.py
  3. 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.

Outputs

Executing this method will return the following:

  1. Process ID: The unique identifier for the started process
  2. Process Name: The name of the started process, typically the name of the Python executable

Method 1 Output

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)
  • Required namespaces: This should be added in the namespaces in the initialize page.
    • System.Diagnostics
    • System.IO and System.Diagnostic were included 

Inputs

You need to pass the following parameters:

  1. PythonExecutable: The path to the Python executable file (ending in .exe) 
    • Example: @"C:\Python39\python.exe"
  2. PythonFile: The path to the Python script you intend to execute
  3. Bool_OP: Set this to true if you want to capture the script's output.
  4. Bool_Error: Set this to true if you want to capture any errors during execution.
  5. Bool_Shell: Set this to true if you want to run the script through the shell.
  6. Bool_ExecuteBackground: Set this to true if you want to execute the script invisibly in the background.

Outputs

  • O_Result: Captures the standard output of the Python script
  • O_Error: Captures any errors produced by the Python script
Python
 
// 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;


Method 2 Output
Method 2 Output - O_Result and O_Error
Method 2 Output - Code

Robotic process automation Python (language) programming langauge

Opinions expressed by DZone contributors are their own.

Related

  • Rust vs Python: Differences and Ideal Use Cases
  • Applying the Pareto Principle To Learn a New Programming Language
  • Start Coding With Google Cloud Workstations
  • Segmentation Violation and How Rust Helps Overcome It

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!