Orblealpha

Python SDK

Install

Requires Python 3.9 or later. Import the package as orble.

$ pip install orble-sdk
main.py
import 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 login

Configure 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.

client.py
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.tech

Calls

orble.create( size=None, name=None, from_snapshot=None, )

Create a box and return a Box instance. Set size to micro, s (default), m or l, and from_snapshot to a snapshot name

orble.Box(name)

Get a client-side reference to an existing box by name

orble.boxes()

Return the account's boxes as a list of Box instances

orble.snapshots()

Return available snapshots as a list of Snapshot instances

box.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 a Result containing code, stdout, stderr and timed_out

box.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=True

box.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 Box instances

box.snapshot(name=None)

Create a snapshot of the box and return a Snapshot instance

box.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 with on=False

box.delete()

Permanently delete the box and its disk

box.refresh()

Retrieve the current API representation as a dictionary and update box.info

box.state

Current lifecycle state of the box, such as running or suspended

snapshot.delete()

Permanently delete the snapshot

Commands, files and ports

Commands

Commands are executed with /bin/sh -c as the agent user in /home/agent, with passwordless sudo available, or as root in /root with the user option. Maximum timeout: 600 seconds; exit code on timeout: 124. Output is limited to the last 64 KiB of each stream

Files

Relative file paths are resolved from /home/agent. Files are streamed in both directions. Maximum file size: 4 GiB

Suspended boxes

Suspended boxes are resumed automatically for command execution and file reads or writes

Ports

Private ports require account authentication. Public ports are accessible without authentication. Token ports require the port's token in the X-Orble-Preview-Token header, or ?orble_preview_token=<token> on a browser link. Public and token ports require account credit. Limit: 20 shared ports per box

Errors

SDK exceptions: orble.Error in Python and OrbleError in TypeScript, with the HTTP status and error message