import Riza from '@riza-io/api';

const pythonCode = `
import sys
import os

print("stdin", sys.stdin.read())
print("args", sys.argv)
print("env", dict(os.environ))
`;

const riza = new Riza();

async function main() {
  const resp = await riza.command.exec({
    language: "PYTHON",
    code: pythonCode,
    stdin: "Hello", 
    args: ["one", "two"],
    env: {
      "DEBUG": "true",
    }
  });
  console.log(resp.stdout);
}

main();
stdin Hello
args ['/src/code.py', 'one', 'two']
env {'DEBUG': 'true'}

Your script has access to input data from three sources: stdin, command line arguments and environment variables.

stdin

The execute code endpoint accepts a string stdin parameter. The API sets any value you provide as stdin for the executed script.

Command line arguments

You can provide a list of strings to the execute code endpoint via the args parameter. The API passes these values as command line arguments to your script.

When accessed within a script, the first argument will always be the absolute path to the file containing the script’s source code. The value is meaningless outside of the Riza environment.

Environment variables

You can provide string key-value pairs to the execute code endpoint via the env parameter. The API sets these values as environment variables accessible from within your script.

import Riza from '@riza-io/api';

const pythonCode = `
import sys
import os

print("stdin", sys.stdin.read())
print("args", sys.argv)
print("env", dict(os.environ))
`;

const riza = new Riza();

async function main() {
  const resp = await riza.command.exec({
    language: "PYTHON",
    code: pythonCode,
    stdin: "Hello", 
    args: ["one", "two"],
    env: {
      "DEBUG": "true",
    }
  });
  console.log(resp.stdout);
}

main();
stdin Hello
args ['/src/code.py', 'one', 'two']
env {'DEBUG': 'true'}