Your script has access to initial input data from four sources: files, stdin,
command line arguments and environment variables.
Files
See the files reference documentation.
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();
from rizaio import Riza
CODE = """
import sys
import os
print("stdin", sys.stdin.read())
print("args", sys.argv)
print("env", dict(os.environ))
"""
client = Riza()
resp = client.command.exec(
language="python",
code=CODE,
stdin="Hello",
args=["one", "two"],
env={
"DEBUG": "true",
}
)
print(resp.stdout)
package main
import (
"context"
"log"
"log/slog"
"github.com/riza-io/riza-api-go"
)
const pythonCode = `
import sys
import os
print("stdin", sys.stdin.read())
print("args", sys.argv)
print("env", dict(os.environ))
`
func main() {
client := riza.NewClient()
params := riza.CommandExecParams{
Language: riza.F(riza.CommandExecParamsLanguagePython),
Code: riza.F(pythonCode),
Stdin: riza.F("Hello"),
Args: riza.F(
[]string{"one": "two"},
),
Env: riza.F(
map[string]string{"DEBUG": "true"},
),
}
resp, err := client.Command.Exec(context.TODO(), params)
if err != nil {
log.Fatal(err)
}
slog.Info(
resp.Stdout,
"code", resp.ExitCode,
"stderr", resp.Stderr,
)
}
stdin Hello
args ['/src/code.py', 'one', 'two']
env {'DEBUG': 'true'}