Skip to main content

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.

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.

Testing a driver

lab_sync_driver_sdk.testing.run_command runs one command in-process, applying the same output validation the host applies:

from lab_sync_driver_sdk.testing import run_command

result = await run_command(Greeter(), "Greet", {"name": "lab"})
assert result == {"Greeting": "Hello, lab!"}

Connection settings

@settings() plus the typed input decorators declare the form an operator fills in. connect receives the saved values in one of two shapes:

# The dict, keyed by display name, beside a carrier that holds the form.
@settings()
@string_in("Host", "device address", default="10.0.0.1")
async def connection_settings(self) -> None: ...

async def connect(self, settings: dict[str, Any] | None = None) -> None:
    host = str((settings or {}).get("Host", "10.0.0.1"))

# Or one parameter per setting, with @settings() on connect itself.
@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, port: int) -> None: ...

In the second shape 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. See lab_sync_driver_sdk.settings_binding.

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

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lab-sync-driver-sdk 0.3.0
File Size Uploaded Provenance Actions
lab_sync_driver_sdk-0.3.0.tar.gz 30.1 kB Without provenance Details for lab_sync_driver_sdk-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lab-sync-driver-sdk 0.3.0
File Interpreter ABI Platform Actions
lab_sync_driver_sdk-0.3.0-py3-none-any.whl Python 3 none any Details for lab_sync_driver_sdk-0.3.0-py3-none-any.whl

Total release size: 62.7 kB

Release files / lab_sync_driver_sdk-0.3.0.tar.gz

Download URL lab_sync_driver_sdk-0.3.0.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e08bce40ade55dcb6505dc5faf6829e7370f77480872b6271547fffd0e859034
BLAKE2b-256 checksum
How to use checksums
409a796e7d1bdb4d2e56ca1f1fed545b3c155ced64bc2543e95416fb56e33e5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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.3.0-py3-none-any.whl

Download URL lab_sync_driver_sdk-0.3.0-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f829f40cabe460ebf2bb6a35e066daee30d1744e6fe0f112c622d4e1c35433ac
BLAKE2b-256 checksum
How to use checksums
99cf8873d933b3e81f65429dcf3834fb9e61af5b1ef233f8bda90f062bc0bf39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page