Qu

python_exec

Builtin index · File I/O

result = python_exec(code, [vars=]) / js_exec(code, [vars=])

Input: code, vars · Output: result

What it is

Runs code (string, source in the guest language) as a subprocess. vars (optional, a Record) is injected into the guest as ordinary variables. The guest writes its result as JSON to an injected output-path variable (_qu_output_path), which this call reads back.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = python_exec(code, [vars=]) / js_exec(code, [vars=])
code stringRuns code (string, source in the guest language) as a subprocess.
vars Record, optionalvars (optional, a Record) is injected into the guest as ordinary variables.
result —
Returns a record {stdout, stderr, success, exit_code, result}: captured output streams, whether the process exited cleanly, its exit code, and the parsed JSON result. For a library with no Qu equivalent yet — and a dependency to be honest about in anything published using it.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

py = python_exec("result = 1 + 1\nimport json\njson.dump(result, open(_qu_output_path, 'w'))")
print(py.result)                         # 2


py2 = python_exec("import json\nresult = x * 2\njson.dump(result, open(_qu_output_path, 'w'))", vars={x=21})
print(py2.result)                        # 42


js = js_exec("const fs = require('fs'); fs.writeFileSync(_qu_output_path, JSON.stringify(1 + 1));")
print(js.result)                         # 2

output
2
42
2

from file-io

How it works

python_exec(code, [vars=]) (§ Python interop, 2026-08-26, contract (temp-file JSON data exchange, python/python3 discovery, the .result field convention).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

js_exec — documented in the same entry.