Skip to main content

labwire-ophyd

Expose any ophyd device as a Labwire instrument, so AI agents can discover and drive the largest existing body of Python instrument drivers through one protocol, with the units, safety classes, and signed results ophyd itself does not carry.

ophyd abstracts hardware for Python programmers. Labwire describes hardware to AI agents. This bridge composes them; Labwire does not reimplement drivers.

Five-minute quickstart

Nothing here needs hardware. From a checkout with make setup done:

# 1. See what the bridge works out on its own, and what it cannot
uv run labwire-ophyd annotate ophyd.sim:motor -o labwire-ophyd.yaml

# 2. Fill in every TODO in that file (ophyd.sim reports no units at all),
#    then check what Labwire would expose
uv run labwire-ophyd check ophyd.sim:motor --annotations labwire-ophyd.yaml

# 3. Watch a full scan run through the protocol, with signed evidence
make demo-ophyd

labwire-ophyd check prints the resolved instrument: every channel with its UCUM unit, every command with its safety class:

OK: SynAxis (motor)
  2 channel(s), 4 component(s), 3 command(s)
    S1  read
    S2  move
    S0  stop
    motor: mm
    motor_setpoint: mm

Serving it is a few lines:

from labwire.bridges.ophyd import OphydInstrument, load_annotations
from labwire.core import InstrumentServer

instrument = OphydInstrument(device, load_annotations(Path("labwire-ophyd.yaml")))
server = InstrumentServer(instrument, confirmation_token="operator-grant")
async with server.serve_websocket("127.0.0.1", 9520):
    ...

The annotation file

ophyd knows a device's structure but not its meaning: ophyd.sim devices report no units, EPICS reports free-text .EGU strings, and ophyd has no concept of a safety class at all. The annotation file supplies exactly that layer, and it is what makes a device safe for an agent to operate.

version: 1
devices:
  ophyd.sim.SynAxis:                 # keyed by class; subclasses inherit it
    description: A sample stage.
    intent_tags: [motion]
    components:
      readback:
        unit: mm                     # UCUM, never guessed for you
        qudt_quantity_kind: Length
        dtype: float64               # ophyd infers dtype from the current value
      setpoint: {unit: mm, dtype: float64}
      velocity: {unit: mm/s}
      acceleration: {unit: mm/s2}
    commands:
      trigger: {exclude: true}       # meaningless for a stage
      move: {estimated_duration_s: 2.0}

instances:
  fine_stage:                        # keyed by Device.name; overrides the class
    components:
      setpoint: {limits: {low: -5.0, high: 5.0}}

Rules worth knowing:

  • Merging is per field, along the class MRO and then the instance, so an override touches only what it names.
  • Unknown keys, components, and commands are errors. A typo that silently annotated nothing would be worse than a failure.
  • Missing units are refused, naming the exact component and the YAML path that would fix it. --allow-partial omits those components instead, and still reports every one.
  • Annotated limits intersect with the device's own control limits: the tightest bound on each side wins.
  • settable: false keeps a channel but removes its actuation command, for the readings ophyd technically lets you write, such as a detector's computed value.

A working example lives at examples/ophyd_scan/labwire-ophyd.yaml.

Mapping

ophyd Labwire
Device.name instrument serial number (model = class name)
Kind.hinted / Kind.normal telemetry channel
Kind.config descriptor metadata
Kind.omitted skipped
describe()[…]["units"] UCUM unit, after EGU translation
lower_ctrl_limit / upper_ctrl_limit parameter minimum / maximum
Device.set() on a positioner move, safety class S2
signal.set() elsewhere set_<attr>, safety class S2
Device.trigger() trigger, safety class S1
Device.stop() stop, safety class S0
command/cancel refused for most commands; EpicsMotor-family moves declare abort and settle only what the status object confirms
ophyd failures HardwareFaultError / DeviceTimeoutError

Safety defaults lean toward friction, because ophyd carries no safety information and guessing low is the failure that moves hardware: actuation is S2 (an agent must present an operator confirmation), acquisition is S1, and stop is S0 so recovery stays available even while an interlock is tripped. Changing a class takes an explicit annotation, never a heuristic.

DESIGN.md has the full reasoning, including why positioners are moved rather than poked.

Why this bridge declares no resources

Protocol v0.3 added resources for instrument state that is a tree with nowhere else to live. An ophyd device has none: its structure is fixed by its class and is already fully expressed as the descriptor plus scalar channels, so inventing a resource here would be adding surface to prove a point. The bridge declares resources: [], which costs a signal-shaped instrument exactly nothing, and that asymmetry is useful evidence about the primitive itself.

One v0.3 change does reach this bridge: a CommandAnnotation.safety_class of S3 now genuinely bites. An S3 command requires an operator grant from a server-side store (labwire grant), and a server with S3 commands and no store refuses to start; see SPEC 8.6 before raising a command's class.

LIMITATIONS

Read this before believing anything above.

  • No physical hardware, ever. The bridge is exercised against ophyd.sim devices and against a pure-Python EPICS soft IOC (caproto) over Channel Access. It has never been connected to a real instrument, a production IOC, or any beamline, and no claim is made about NSLS-II, APS, Diamond, or any other facility.

  • Classic synchronous ophyd only. ophyd-async is not supported.

  • Units are validated for presence, not grammar. The EGU→UCUM table covers conventional beamline spellings and is convention-based; it has not been checked against a UCUM implementation.

  • Cancellation is declared per command, and the record earns its claims. ophyd.sim axes' stop() is literally pass (their move completes no matter what), so their move declares cancel_semantics: "none" and a mid-run cancel is refused rather than reported as done. EpicsMotor-family devices declare "abort", because their stop() writes the motor record's .STOP field; after a stop, the move's status object must resolve within a settlement window before the record claims a halt, and otherwise the settlement is "unconfirmed", which means exactly what it says. An annotation may downgrade any command to "none"; declaring "abort" in an annotation is a truth claim about the bench, not a preference. TODO-VERIFY: the abort path has never run against a real EPICS IOC.

  • ophyd is synchronous. Every call runs in a worker thread, so the server keeps answering, but a badly behaved device still occupies a thread.

  • Array- and enum-valued signals are refused: Labwire v0.2 channels carry scalars, and non-numeric channels still need an explicit unit.

  • Move progress is not reported. MoveStatus.watch() yields no useful intermediate fractions on simulated devices, so the bridge does not fabricate one.

Licensing

ophyd is a separate BSD-3 project from the Bluesky collaboration (Brookhaven National Laboratory and contributors), and caproto is BSD-3 as well. Both are optional dependencies here: not vendored, not forked, not modified. See the repository NOTICE.

Metadata

Release files for labwire-ophyd 0.4.1

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

Source distribution (sdist)

Source distribution for labwire-ophyd 0.4.1
File Size Uploaded Provenance Actions
labwire_ophyd-0.4.1.tar.gz 35.8 kB With provenance Details for labwire_ophyd-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for labwire-ophyd 0.4.1
File Interpreter ABI Platform Actions
labwire_ophyd-0.4.1-py3-none-any.whl Python 3 none any Details for labwire_ophyd-0.4.1-py3-none-any.whl

Total release size: 62.0 kB

Release files / labwire_ophyd-0.4.1.tar.gz

Download URL labwire_ophyd-0.4.1.tar.gz
Size 35.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1481ff02199b92ee47c3fee2f3c35c03e22fd5674c9e3352131dc8986f701563
BLAKE2b-256 checksum
How to use checksums
a132eb25a15656f0abe46877ef0cf9dd5ad39a806548b3352c164d200320c815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

Release files / labwire_ophyd-0.4.1-py3-none-any.whl

Download URL labwire_ophyd-0.4.1-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2f38b57a186ae5e6e766336b327efa3ef5f7a52949ecde15cdcca7f5290edd5
BLAKE2b-256 checksum
How to use checksums
54d7a3af86a4967d8f6caac4d2a9c3fd922dde7190e8ce523a4e79fb69c4a7f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

Security for labwire-ophyd 0.4.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for labwire_ophyd-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

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