Search code examples
pythonprocessballerina

Ballerina: How to call python code from inside Ballerina


I have a ballerina backend with an http listener running. When I receive a request, want to call a python script that will take the arguments, plot a graph, and save it as png. Then returns png path to ballerina backend.

resource function get [string year]/[string round]/laps/[string driverName] () returns string|error {
  string graphPath = < call python code with args (year, round, driverName) >
  return graphPath
}

If it's not possible to directly call, please tell me how I can invoke OS command? This answer seems outdated.


Solution

  • OS command execution support in Ballerina will be available with the upcoming Swanlake Update 2 release through the os:Exec() function.