# Control with Workspace RPC

> Documentation version: 3.0
> HTML: https://docs.flarelive.manifolddynamics.com/manual/operation/rpc.html
> [Complete contents](https://docs.flarelive.manifolddynamics.com/contents.md) · [Agent index](https://docs.flarelive.manifolddynamics.com/llms.txt)

**Workspace RPC (`flarelive-client`) is the recommended interface for controlling Flare Live from Python.** It covers scene construction, inspection, editing, project files, simulation and export. Your script runs in your own Python environment and controls the scene in an already running GUI or headless instance.

You need Python **3.10 or newer**, an [activated Flare Live installation](https://docs.flarelive.manifolddynamics.com/manual/installation-and-activation.md), and the client wheel supplied in that installation's `python` folder. Run Flare Live and the script as the same OS user.

## Install the client

Create and activate an environment for your scripts. Install the wheel supplied with the version of Flare Live you will control. Run subsequent examples with `python` in this activated environment.

### Windows PowerShell

Set `$flareLiveBin` to the folder containing `flare-live-cli.exe`:

```powershell
$flareLiveBin = 'C:\Tools\FlareLive\bin'
python -m venv .venv-flarelive
.\.venv-flarelive\Scripts\Activate.ps1
$clientWheel = Get-ChildItem -LiteralPath "$flareLiveBin\python" -Filter 'flarelive_client-*.whl' | Select-Object -First 1
python -m pip install $clientWheel.FullName
```

If PowerShell prevents activation, use `.\.venv-flarelive\Scripts\python.exe` in place of `python` in the examples.

### Linux

For an extracted runtime package, locate `flarelive_client-*.whl` in the `python` folder beside `flare-live-cli`.

For an AppImage, extract a copy to obtain its wheel. Replace `FlareLive.AppImage` with your downloaded filename:

```sh
chmod +x ./FlareLive.AppImage
./FlareLive.AppImage --appimage-extract
python3 -m venv .venv-flarelive
. .venv-flarelive/bin/activate
flarelive_wheel="$(find "$PWD/squashfs-root" -name 'flarelive_client-*.whl' -print -quit)"
python -m pip install "$flarelive_wheel"
```

You can continue launching the original AppImage. The extracted copy supplies the client wheel for this environment.

## Connect and inspect

Open the GUI or start [headless mode](https://docs.flarelive.manifolddynamics.com/manual/operation/index.md#headless), then keep that instance running. Save this as `inspect_scene.py`:

```python
from flarelive_client import connect

with connect() as client:
    ws = client.workspace
    print("Project:", ws.state.document_file or "(unsaved document)")
    for obj in ws.list_objects():
        print(obj.name, obj.class_name)
```

Run it in your activated environment:

```sh
python inspect_scene.py
```

`connect()` selects the single running instance. The script reads that instance's current scene. Use the same connection for editing, simulation and export; GUI and headless instances expose the same Workspace operations.

## Edit and save a scene

While in **Document**, an RPC edit has the same persistence rules as a GUI edit: it changes the current scene and enters editing history. Call `save_world` or use **File > Save** to write the preparation to disk. Closing the client leaves committed edits in the application; it does not save an FLL automatically.

For example, with Simulation stopped and no Experiment active, this script adds a Camera to the current Document and saves a separate project:

```python
from pathlib import Path
from flarelive_client import connect

PROJECT = Path("prepared-scene.fll").resolve()

with connect() as client:
    ws = client.workspace
    camera = ws.create_object("simexp.core.camera")
    ws.set_property(camera, "name", "Observer")
    ws.save_world(PROJECT)
```

`save_world()` with no path saves to the Document's existing filename. The call returns after the file is written successfully.

For complex scenes, prepare and save an FLL once. A trial script can open it with `ws.open_world(Path("prepared-scene.fll").resolve())`, begin an Experiment for temporary changes, initialize, run, then Clear and End experiment. Save reusable changes in Document before starting the trial. See [world lifecycle](https://docs.flarelive.manifolddynamics.com/manual/concepts/lifecycle.md) and [projects and saving](https://docs.flarelive.manifolddynamics.com/manual/gui/projects.md).

Continue with [inspection queries](https://docs.flarelive.manifolddynamics.com/reference/api/inspection.md), [Workspace editing](https://docs.flarelive.manifolddynamics.com/reference/api/workspace.md) or a complete [simulation loop](https://docs.flarelive.manifolddynamics.com/manual/control/simulation.md). The [vehicle tutorials](https://docs.flarelive.manifolddynamics.com/manual/tutorials/index.md) use this same RPC connection.

## Multiple instances

When several Flare Live processes are running, list them with `flare-live-cli instances` (Windows adds `.exe`; an AppImage uses `./FlareLive.AppImage --cli instances`). Each entry includes an ID, process ID and project path.

Replace `connect()` with `connect(instance_id="INSTANCE_ID")`, using the desired ID or a unique prefix. For CLI commands targeting an existing instance, append `--instance INSTANCE_ID`. All other examples assume one running instance and omit this selector.

## If connection fails

| Result | What to check |
| --- | --- |
| `ModuleNotFoundError: flarelive_client` | Install the wheel and run the script with the same Python environment. |
| No matching instance | Start the GUI or CLI `serve` as the same OS user, then connect again. |
| Multiple matching instances | Follow [Multiple instances](#multiple-instances) to select the desired process. |
| Missing method or version mismatch | Install the wheel supplied with the target Flare Live version. Use pip `--force-reinstall` when replacing a wheel with the same version. |
