Using the SDK
Quick Start
-
Set the
FOREVERVM_TOKEN
environment variable:FOREVERVM_TOKEN=*** -
Connect to a machine and run some code:
from forevervm_sdk import Replwith Repl() as repl:instruction = repl.exec('4 + 4')print(instruction["result"])import { Repl } from "@forevervm/sdk";const repl = new Repl();const instruction = repl.exec("4 + 4");console.log(await instruction.result);
Example
Below, you can see a short example of how to use the ForeverVM SDK.
import osfrom forevervm_sdk import ForeverVM
token = os.getenv('FOREVERVM_TOKEN')
# Initialize ForeverVMfvm = ForeverVM(token)
# Connect to a new machinewith fvm.repl() as repl:
# Execute some code exec_result = repl.exec('4 + 4')
# Get the result print('result:', exec_result.result)
# Execute code with output exec_result = repl.exec('for i in range(10):\n print(i)')
for output in exec_result.output: print(output["stream"], output["data"])
import { ForeverVM } from "@forevervm/sdk";
const token = process.env.FOREVERVM_TOKEN;
// Initialize ForeverVMconst fvm = new ForeverVM({ token });
// Connect to a new machine.const repl = fvm.repl();
// Execute some codelet execResult = repl.exec("4 + 4");
// Get the resultconsole.log("result:", await execResult.result);
// We can also print stdout and stderrexecResult = repl.exec("for i in range(10):\n print(i)");
for await (const output of execResult.output) { console.log(output.stream, output.data);}
process.exit(0);
Reference
Continue to the next section to see a reference of the SDK classes and methods.