Cross runner for communication with other languages.
If this is a brand new project, make sure to create a package.json first with the npm init
command.
Installation is done using the npm install command:
npm install starless-crossrunner
const { invokePython } = require("starless-crossrunner");
invokePython("main.py", "Hello to python");
invokePython("main.py", { name: "hlm", hobby: "coding" });
import sys
import json
info = json.loads(sys.argv[1]) # { name: "hlm", hobby: "coding" }
import sys
import json
info = json.loads(sys.argv[1]) # { name: "hlm", hobby: "coding" }
print(json.dumps(info)) # send result back to js
const result = await invokePython("main.py", { name: "hlm", hobby: "coding" });
console.log(result); // { name: "hlm", hobby: "coding" }
invokePython("main.py", "Hello to python", {
venvPath: "...", // path to venv folder
});
invokePython("main.py", "Hello to python", {
venvPath: "...", // conda env
isConda: true,
});
invokePython("main.py", "Hello to python", {
pythonPath: "...",
});