Python SDK
Install
Requires Python 3.9 or later. Import the package as orble.
$ pip install orble-sdkimport orble
box = orble.create(size="s")
r = box.exec("npm test", cwd="app", env={"CI": "1"})
print(r.code, r.stdout)
box.delete()
Authentication
Authenticate with an API key or with credentials saved by the Orble CLI. The SDK loads credentials automatically unless you provide a key when configuring a client.
Use an API key
Create an API key in Settings, then set ORBLE_API_KEY in the environment where your application runs.
$ export ORBLE_API_KEY=orble_...Use CLI credentials
For local development, run orble login to save credentials. If no key is provided explicitly or through ORBLE_API_KEY, the SDK uses the saved CLI token.
The default configuration file is ~/.config/orble/config.json on Linux, ~/Library/Application Support/orble/config.json on macOS, or %APPDATA%/orble/config.json on Windows. On Linux, XDG_CONFIG_HOME overrides the ~/.config directory.
$ orble loginConfigure a client
Pass credentials directly when you need an explicitly configured client. The client key takes precedence over ORBLE_API_KEY and CLI credentials. Pass the client with client= to SDK functions or to orble.Box.
import os
import orble
client = orble.Client(
key=os.environ["ORBLE_API_KEY"],
url="https://orble.tech",
)
box = orble.Box("my-box", client=client)
Choose an API URL
Set ORBLE_API_URL to use another Orble deployment, such as staging. Use credentials created for that deployment.
The SDK selects the URL in this order: the client's explicit url argument, ORBLE_API_URL, the API URL saved by the CLI, then https://orble.tech.
$ export ORBLE_API_URL=https://staging.orble.techCalls
orble.create( size=None, name=None, from_snapshot=None, )Create a box and return a
Boxinstance. Setsizetomicro,s(default),morl, andfrom_snapshotto a snapshot nameorble.Box(name)Get a client-side reference to an existing box by name
orble.boxes()Return the account's boxes as a list of
Boxinstancesorble.snapshots()Return available snapshots as a list of
Snapshotinstancesbox.exec( command, timeout=None, env=None, cwd=None, user=None, )Execute a shell command and wait for completion. Set
user="root"to run it as root. Return aResultcontainingcode,stdout,stderrandtimed_outbox.write(path, content, user=None)Write text, bytes or a file opened in binary mode to a file, replacing existing contents and creating missing parent directories
box.read(path, binary=False, user=None)Read a whole file as text, or as bytes when
binary=Truebox.port(port, public=False)Expose a port and return its HTTPS URL. Access is restricted to the account unless public access is requested
box.token_port(port)Expose a port to anyone with its token. Return
{"url", "token"}box.new_port_token(port)Replace a token port's token and return the new
{"url", "token"}box.fork(count=1)Create 1–10 copies of the box with disk contents, memory and process state preserved. Return the copies as a list of
Boxinstancesbox.snapshot(name=None)Create a snapshot of the box and return a
Snapshotinstancebox.suspend()Suspend the box with guest memory and process state preserved
box.resume()Resume the box from its saved memory and process state
box.start()Start a stopped box (its own software powered it off) from its disk. Nothing else wakes a stopped box
box.keep_awake(on=True)Disable automatic suspension when
on=True; restore suspension when idle withon=Falsebox.delete()Permanently delete the box and its disk
box.refresh()Retrieve the current API representation as a dictionary and update
box.infobox.stateCurrent lifecycle state of the box, such as
runningorsuspendedsnapshot.delete()Permanently delete the snapshot
Commands, files and ports
CommandsCommands are executed with
/bin/sh -cas theagentuser in/home/agent, with passwordless sudo available, or asrootin/rootwith theuseroption. Maximum timeout: 600 seconds; exit code on timeout: 124. Output is limited to the last 64 KiB of each streamFilesRelative file paths are resolved from
/home/agent. Files are streamed in both directions. Maximum file size: 4 GiBSuspended boxesSuspended boxes are resumed automatically for command execution and file reads or writes
PortsPrivate ports require account authentication. Public ports are accessible without authentication. Token ports require the port's token in the
X-Orble-Preview-Tokenheader, or?orble_preview_token=<token>on a browser link. Public and token ports require account credit. Limit: 20 shared ports per boxErrorsSDK exceptions:
orble.Errorin Python andOrbleErrorin TypeScript, with the HTTPstatusand error message