lab-sync-driver-sdk
Write a lab device driver as a decorated Python class and serve it as a
supervised child process. A driver subclasses Device, decorates async
methods with @command and the typed in/out decorators, and calls
serve(device) to speak the stdio wire protocol defined by
lab-sync-driver-protocol. The SDK depends on
nothing but that package, so a driver ships with its own runtime and never
imports the supervisor that launches it.
pip install lab-sync-driver-sdk
A driver
import asyncio
from lab_sync_driver_sdk import Device, command, float_in, string_in, string_out, serve
class Greeter(Device):
device_type_id = "acme-greeter"
manufacturer = "Acme"
model = "Greeter 1"
@command("Greet", "Say hello", default_sim_sec=1.0)
@string_in("Name", "who to greet", default="world", maps_to="name")
@float_in("Delay", "seconds to wait first", default=0.0, min_value=0.0, maps_to="delay")
@string_out("Greeting", "what was said")
async def greet(self, name: str = "world", delay: float = 0.0, progress=None) -> dict[str, object]:
await asyncio.sleep(delay)
if progress is not None:
await progress(1.0, "greeted")
return {"Greeting": f"Hello, {name}!"}
if __name__ == "__main__":
asyncio.run(serve(Greeter()))
The decorators produce the driver's describe reply: its commands, their
inputs and outputs, and any optional metadata the class declares (category,
physical dimensions, default_nests, configurations, telemetry channels).
A command returns a dict, and every key in it must be declared with an output
decorator. An undeclared key fails the command with OutputValidationError.
A command that takes a progress parameter is handed an async
progress(fraction, message) reporter.
A device may define async def abort(self, command_name: str). The host calls
it after cancelling a command's task, with the name of the command that was
cancelled -- so a driver waiting on a run can tell that wait from a
non-exclusive status read cancelled beside it, and stop the hardware only for
the one that owns it. The name is "*" only when the host does not know the
execution being aborted.
Once serve starts, stdout carries protocol frames only. The host points
sys.stdout at stderr, so a stray print lands on the log channel rather
than corrupting a frame.
Moving parts in the 3D views
A device whose 3D model moves declares its joints in articulation (each names
a node in the GLB, or one of its animation clips; see the protocol's
articulation field). Where they are reaches the views as articulation
telemetry frames, only while a view is open.
A part only commands move -- a lid, a door, a stage -- needs no state of the driver's own. Declare it on the commands and the SDK reports it:
from typing import ClassVar
from lab_sync_driver_sdk import UNKNOWN, Device, articulates, bool_in, command, when_param
class Sealer(Device):
articulation: ClassVar[dict[str, object]] = {
"joints": [{"id": "stage", "label": "Stage", "kind": "clip", "clip": "Stage_In"}],
}
@command("Seal", "Take the stage in, seal, bring it out")
@articulates("stage", during=1.0, after=0.0)
async def seal(self) -> dict[str, object]: ...
@command("Load", "Bring the stage in, and out again unless told to hold it")
@bool_in("Hold", maps_to="hold")
@articulates("stage", during=1.0, after=when_param("hold", truthy=1.0, falsy=0.0))
async def load(self, *, hold: bool = False) -> dict[str, object]: ...
@command("Send Command", "A raw line that may move anything")
@articulates("stage", after=UNKNOWN)
async def send_command(self, line: str = "") -> dict[str, object]: ...
during is reported as the command starts and after when it returns (left
out, the joint keeps during). A command that raises or is aborted leaves every
joint it declares unknown, so the views keep the last pose rather than being
told a guess -- a refusal before anything moved included, since the SDK cannot
tell the two apart. when_param picks by one of the method's own keywords,
after defaults; a branch left out leaves the joint as it is.
What a command cannot declare -- a position read from the hardware, the state
seeded at connect -- the driver writes with self.set_joint(id, value) and
self.forget_joint(id), and reads back with self.joint_value(id). One rule
orders every write: it carries the start order of the command it is made in (or
a fresh one outside any command), and is dropped if a command that started
later has already written that joint. A status read asked for before a move
cannot overwrite where the move is taking the part, and a slow command's
after cannot undo a newer command's during.
A device that declares articulation and no @telemetry("articulation")
sampler of its own gets that channel from the host, which pushes the known pose
when a view opens and each change as it is written. A device with a sampler
keeps it, and its readings are filled in with the joints the store knows (the
sample wins for any joint it reads). The declarations apply when a command runs
through the host or run_command; a command method called directly from
Python -- one command calling another, or a test -- is a plain method call.
Testing a driver
lab_sync_driver_sdk.testing.run_command runs one command in-process, applying the
same output validation the host applies and the same @articulates reporting
(read it back with device.joint_value(...)):
from lab_sync_driver_sdk.testing import run_command
result = await run_command(Greeter(), "Greet", {"name": "lab"})
assert result == {"Greeting": "Hello, lab!"}
lab_sync_driver_sdk.model_checks holds a driver's 3D model to what the Device
Hub's 3D views need. It checks:
- the format: a binary glTF 2.0 file, self-contained, with no cameras or lights
- the weight: 50,000 triangles by default, never more than 200,000, and 2 MB
- the frame: metres, +Z up, standing on its origin, and matching the declared envelope
- that every articulation joint finds its node or clip
- that every labware anchor names a declared nest
It reads only the file's JSON chunk, with nothing but the standard library. One call covers every model a driver ships, and an exception is an argument with its reason beside it:
from lab_sync_driver_sdk.model_checks import check_driver_models
def test_the_shipped_models_pass_the_sdk_model_checks() -> None:
assert check_driver_models(Greeter) == []
python -m lab_sync_driver_sdk.model_checks <file.glb> prints the same report
for a file by hand.
Connection settings
@settings() plus the typed input decorators declare the form an operator fills
in. Put them on connect itself, with one parameter per setting — this is the
standard shape, and every driver in this repository uses it:
@settings()
@string_in("Host", "device address", default="10.0.0.1", maps_to="host")
@int_in("Port", "device port", default=4321, maps_to="port")
async def connect(self, host: str = "10.0.0.1", port: int = 4321) -> None: ...
The host binds each parameter by maps_to (else the display name). The value
comes from the saved setting, else the declared default, else the signature's
own default, and is coerced to the declared type, so connect receives an int
even when the value was saved as text. A setting with no matching parameter, or
a required parameter with no setting, fails the connect with a message naming
it. Saved settings are keyed by display name, so adding maps_to to an existing
driver keeps its devices' saved values. A driver that reconnects by itself (on a
simulation switch, say) keeps the keyword arguments of its last connect and
replays them. See lab_sync_driver_sdk.settings_binding.
The older shape — an empty @settings() carrier such as connection_settings
holding the form, beside connect(self, settings) taking the saved dict keyed
by display name — is still served, for drivers written before binding existed,
but new and updated drivers should not use it.
Simulation
The engine switches a device into simulation with set_simulation; override
Device.set_simulation to start or stop a built-in simulator. Beyond that:
-
has_simulator = Trueon the class says the driver runs a full built-in simulator, so every command handles its own simulation -- nohandles_simulation=Trueon each. -
self.simulation_speedis how many times faster than real time the simulation runs. It is not a setting: the host sets it from the engine'sset_simulationbefore yourset_simulation(or a simulatedconnect) runs. It is 1.0 today. Wait withawait self.sim_sleep(real_seconds), or readself.sim_seconds(real_seconds). -
@simulation_settings()declares the simulator's own settings form, apart from the connection settings, bound onto the method like@settings()bindsconnectand called before simulation is applied:@simulation_settings() @float_in("Heat-Up Time (s)", "simulated hot plate", default=150.0, maps_to="heat_up_s") async def configure_simulation(self, heat_up_s: float) -> None: self._heat_up_s = heat_up_s
-
@simulation_action(name, description)declares something an operator can do to the running simulator (fail the next cycle, raise a fault). It is not a command: it runs beside one in flight, only while simulated.@simulation_action("Fail Next Seal", "The next seal ends in this fault.") @string_in("Fault", "the fault", default="No Plate In Holder", maps_to="fault") async def fail_next_seal(self, fault: str) -> None: self._simulator.fail_next = fault
Test them with lab_sync_driver_sdk.testing.simulate(device, speed=, settings=),
which switches a device into simulation the way the host does, and
run_simulation_action(device, name, params). The whole model, including the
engine's own faults, is in docs/device_hub/simulation.md.
Hosting a lab-device-sdk driver
lab_sync_driver_sdk.lab_host serves a driver written against
lab-device-sdk over the same
protocol, unchanged. It needs the lab extra, which also brings in FastAPI
and uvicorn for drivers that serve HTTP routes of their own:
pip install "lab-sync-driver-sdk[lab]"
It hosts one device per process, so it has to be told which instance it is
running. A driver manifest declares that with the supervisor's {device_id}
token rather than a hardcoded id, which is what lets a site run several
devices of the same type:
[launch]
type = "command"
command = ["python", "-m", "lab_sync_driver_sdk.lab_host",
"--device", "my_pkg.my_device:MyDevice",
"--device-id", "{device_id}"]
License
MIT
Metadata
Release files for lab-sync-driver-sdk 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lab_sync_driver_sdk-0.8.0.tar.gz | 63.5 kB | Without provenance | Details for lab_sync_driver_sdk-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lab_sync_driver_sdk-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for lab_sync_driver_sdk-0.8.0-py3-none-any.whl |
Total release size: 128.6 kB
Release files / lab_sync_driver_sdk-0.8.0.tar.gz
| Download URL | lab_sync_driver_sdk-0.8.0.tar.gz |
|---|---|
| Size | 63.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c34b54b22db93ea45ec64243372f21c4ceda478cfec9f6c225db4cef8a0fcca
|
|
BLAKE2b-256 checksum How to use checksums |
07cef84d03a605dcf31ac52b5e9eefc52b4f0286d8f61b94ee5ef64542e75f54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / lab_sync_driver_sdk-0.8.0-py3-none-any.whl
| Download URL | lab_sync_driver_sdk-0.8.0-py3-none-any.whl |
|---|---|
| Size | 65.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66db2a99a1a5b6f33b1918ab01c11b045d1e3c1c056105a26affa0c977dcc129
|
|
BLAKE2b-256 checksum How to use checksums |
99eb94d22f4e9c63987719a4cffe3f7c3fce20ae2dc85d9c04c6b17b11827f37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for lab-sync-driver-sdk 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.