Skip to content

Python environments and secrets

Every Python device runs in an environment of its own, made by LabOrchestra with uv. The Python you installed is only the starting point and is never changed. An environment holds the laborchestra package and the libraries the device asks for, so two devices can need different versions of pyserial without trouble.

A single-file device names its libraries in a header at the top of the file (PEP 723):

# /// script
# requires-python = ">=3.11"
# dependencies = ["pyserial>=3.5"]
# ///

Devices with the same libraries share an environment. Change a library or the Python version and a new environment is made; the old one stays for a while, so a device can go back.

A vendor library that is only available as a 32-bit DLL needs a 32-bit Python: install one, and set python in the device’s entry in devices.json (or Python in the device’s dialog) to the path of its python.exe. LabOrchestra builds the device’s environment from that interpreter.

To choose the Python for a device, set python in its entry in devices.json to a version ("3.12") or the path of an interpreter. Without it LabOrchestra uses an installed Python 3.11 or newer and offers to download one (about 30 MB) if none fits.

The Python environments panel on the Devices page lists them and what uses each one.

The Python environments panel: a list of environments with the devices that use them.The Python environments panel: a list of environments with the devices that use them.

Remove unused for 30 days deletes those that no device has used for that long.

Passwords, tokens and API keys do not belong in devices.json (it may be in git) or in a device’s file. Store them as secrets instead:

  1. On the Devices page open Secrets and add one with a name (slack_token) and its value.

  2. In devices.json, give the option the name instead of the value:

    { "file": "services/slack_notifier.py", "config": { "token": { "secret": "slack_token" } } }

The device receives the value as an ordinary option. Secrets are kept in the app data folder of the server, outside the workspace, so they are not committed and not synced with it. The file is readable only by the account that runs the server; it is not encrypted, so anyone who can sign in to that computer as that user can read it. A device restarts by itself when a secret it uses changes.

The Secrets panel with one secret, slack_token, whose value is shown as dots, and fields to add another.The Secrets panel with one secret, slack_token, whose value is shown as dots, and fields to add another.
From a script, lab.set_secret(name, value) does the same as the panel.