Top-Level Functions
The most common entry points. Import with import mitk_workbench_remote as mw.
- mitk_workbench_remote.connect(url='http://localhost:8080', *, token=None, timeout=30.0, transfer_mode=None, trust_env=None)
Connect to a running MITK Workbench REST server.
No HTTP call is made during construction — the connection is established lazily on first use.
- Parameters:
url (
str(default:'http://localhost:8080')) – Base URL of the Workbench REST server.token (
str|None(default:None)) – Optional API token (Authorization: Bearerheader).timeout (
float(default:30.0)) – Request timeout in seconds.transfer_mode (
str|None(default:None)) – Override transfer mode ("direct"or"file-reference"). WhenNonethe mode is auto-detected from server capabilities on first data request.trust_env (
bool|None(default:None)) – Whether to honor environment proxy settings. WhenNone(default) env proxies are bypassed for loopback URLs and honored for remote hosts — a forward/corporate proxy cannot reach the caller’s own machine, so proxying alocalhostrequest would fail. PassTrueto always honor env proxies orFalseto never.
- Return type:
- Returns:
A
Workbenchhandle ready for use.
- mitk_workbench_remote.discover(ports=range(8080, 8100), *, timeout=0.5)
Probe localhost ports for running MITK Workbench instances.
Probes are executed concurrently. Any port that responds to
GET /api/v1/healthwith a 2xx status is included in the result.
- mitk_workbench_remote.launch(executable=None, *, port=None, token=None, timeout=30.0, extra_args=None)
Start a new MITK Workbench process with the REST API enabled.
Spawns the process, waits for the REST server to become healthy, and returns a connected
Workbenchhandle.On Windows the shipped launcher is a
.batwrapper thatstart /Bdetaches the realMitkWorkbench.exe; the trackedcmd.exethen exits 0 within ~0.1 s, long before the REST server is up.launch()therefore tolerates an exit code of 0 and keeps polling/health; only a non-zero exit is treated as an immediate failure. The trade-off: a direct executable that genuinely exits 0 right away (e.g.--help) is not detected until thetimeoutdeadline rather than instantly.The child’s stderr is redirected to a temp file (never an inherited PIPE, which the detached exe would hold open and deadlock on). On success the file is removed by
shutdown(); on a failed launch it is removed before raising. Any failure also kills the process listening onport(the detached exe), since a raisedlaunch()returns no handle for the caller to clean up later.- Parameters:
executable (
str|Path|None(default:None)) – Path to the MITK Workbench executable. WhenNone, theMITK_WORKBENCHenvironment variable is used. Pass either this argument or set the env var.port (
int|None(default:None)) – Port for the REST server. WhenNone, the first free port in 8080-8099 is chosen automatically.token (
str|None(default:None)) – API token for the new server. WhenNone, a secure random 32-character hex token is generated.timeout (
float(default:30.0)) – Maximum seconds to wait for the server to become healthy before giving up.extra_args (
list[str] |None(default:None)) – Additional command-line arguments appended after the preference patch XML file reference.
- Return type:
- Returns:
A
Workbenchhandle backed by the newly started process.- Raises:
MitkError – If
executableisNoneandMITK_WORKBENCHis not set, if no free port is available, or if the Workbench process exits immediately with a preference-patch failure.FileNotFoundError – If the resolved executable path does not exist.
MitkConnectionError – If the server does not become healthy within
timeoutseconds.