Hi Team - Need help. How to call a Python SDK from UiPath.
My source team build a Python SDK is for 10 HTTP API (GET & POST) calls. So far i implemented calling API calls using HTTP activity, but never called a Python SDK which will perform these steps.
Please share the steps or any sample code so that i can go through and build my own logic.
Thanks in advance.
You can consider using below activities instead to directly interact with python:
Hope this helps.
Regards
Sonali
Thanks @sonaliaggarwal47 , But what about SDK ?
sdk would have a py file which can be called using run python scripton sdk again when it can be done natively using http request??
also why do you want to use pyth
cheers
I tested this solution in the past. You can adjust based on your needs.
Invoke Code C# to retrieve the output from a Python Script in UiPath Studio:
Installers:
https://download.uipath.com/versions/24.10.10/UiPathStudio.msi
https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe
UiPath Studio 24.10.10
Windows project compatibility
UiPath.System.Activities.24.10.7
Import these namespaces:
System
System.Diagnostics
Invoke Code activity for Language C#:
// Path to the Python executable
//string pythonPath = @"C:\Program Files\Python312\python.exe";
// Path to the Python script
//string scriptPath = @"C:\Users\admin_1\Documents\PythonScriptToExecute.py";
// Create a new process to run the Python script
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = pythonPath;
start.Arguments = scriptPath;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
start.CreateNoWindow = true;
// Start the process
using (Process process = Process.Start(start))
{
// Read the output from the Python script
using (System.IO.StreamReader reader = process.StandardOutput)
{
result = reader.ReadToEnd();
//Console.WriteLine("Output: " + result); // Print the result to verify
}
// Read any error messages from the Python script
using (System.IO.StreamReader reader = process.StandardError)
{
string error = reader.ReadToEnd();
if (!string.IsNullOrEmpty(error))
{
Console.WriteLine("Error: " + error);
}
}
}
Invoked code arguments
result -> out -> System.String -> out_PythonScript
pythonPath -> in -> System.String -> "C:\Program Files\Python312\python.exe"
scriptPath -> in -> System.String -> "C:\Users\admin_1\Documents\PythonScriptToExecute.py"
PythonScriptToExecute.py content
def add_numbers(a, b):
return a + b
# Example usage
out_results = add_numbers(5, 3)
print(out_results)
Results:
1 Like

