Skip to main content

raydriver

Rust-native machine drivers for Rayforge, exposed to Python via PyO3.

Currently this provides a full port of Rayforge's advanced GRBL serial driver: character-counting flow control, handshake and status polling, interactive command queue, job streaming with stall detection and deadlock recovery, cancel/safety-shutdown semantics, settings and WCS access, and probe cycles. ESP3D/FluidNC controllers use the same GRBL session over an HTTP command endpoint and WebSocket response channel, with upload-and-execute jobs. Dialects (command templates) remain data owned by Rayforge and are passed in resolved form. GRBL sessions can also connect over Bluetooth Classic SPP/RFCOMM on Linux, macOS and Windows, once the device is paired by the operating system.

CLI

The raydriver command runs G-code against a real device with live progress, or against the built-in firmware emulator for hardware-free dry runs:

raydriver run job.gcode --port /dev/ttyUSB0 --baudrate 115200
raydriver run job.gcode --emulator          # no hardware needed
raydriver status --port /dev/ttyUSB0 --seconds 5

Ruida controllers consume rpascript instead of G-code; run sends the whole script and waits for the controller to report idle:

raydriver run job.rds --protocol ruida --host 192.168.1.50
raydriver run job.rds --protocol ruida --usb-device /dev/ttyUSB0
raydriver run job.rds --protocol ruida --emulator --no-wait

While a GRBL job runs, raydriver run shows acknowledged lines, a progress bar, the device state, machine position, feed rate and ETA; Ctrl-C cancels the job and runs the safety shutdown. The same cancel path sends STOP_JOB to a Ruida controller.

API reference

The Python API reference under docs/api is generated from the .pyi type stubs. Regenerate it after changing the Rust bindings:

make docs

Daemon (remote sessions)

The daemon runs the driver next to the hardware — e.g. on a Raspberry Pi in the workshop — while Rayforge runs on your desk. Jobs run daemon-side and survive client disconnects. Works on Linux, macOS and Windows; full reference in docs/daemon.md.

1. Add your machine

pip install raydriver          # includes network discovery
raydriver scan                 # find your machine's serial port
raydriver daemon add /dev/ttyUSB0

add creates the config file on first use and generates a token — the password clients use to connect. It prints the token; raydriver daemon status shows it again later. The config lives in ~/.config/raydriver/daemon.json (Linux), ~/Library/Application Support/raydriver/daemon.json (macOS) or %APPDATA%\raydriver\daemon.json (Windows).

The daemon announces itself over mDNS, so Rayforge's machine wizard discovers it automatically — no manual network setup.

Defaults are GRBL at 115200 baud; for other firmware use raydriver daemon add PORT --protocol smoothie --baudrate 115200 (protocols: grbl, grbl_simple, smoothie, marlin, octoprint; ESP3D and FluidNC sessions are configured in daemon.json with their host and HTTP/WebSocket ports). xTool network sessions are local-only and are not hosted by the daemon. raydriver daemon remove PORT unconfigures a device.

2. Run the daemon

raydriver daemon               # foreground
raydriver daemon install       # or as a service

install uses a systemd user unit on Linux, a launchd LaunchAgent on macOS and a logon scheduled task on Windows. raydriver daemon status shows the service state and probes the daemon; raydriver daemon uninstall stops and removes it.

3. Check it

raydriver list                 # configured devices + connection state
raydriver connection           # connected clients + control lease
raydriver info 127.0.0.1:8765  # sessions, devices and cameras

Connecting clients

Exposing the daemon to the LAN

On loopback the token never leaves the machine, so no TLS is needed. Reaching the daemon from another computer requires a certificate and a non-loopback bind — an exposed listener refuses to start without both a token and TLS. See docs/daemon.md for the setup.

Protocol analyzer

The analyzer captures device traffic, decodes it to a readable listing, and replays or proxies it — the workflow for developing protocols without hardware and for characterizing real controllers. Captures are editable JSONL (text lines or base64 for binary protocols), and decoders plug in per protocol (grbl and ruida ship; raw and hex cover the rest).

# Record a session (or --emulator for a hardware-free dry run)
raydriver analyzer record --port /dev/ttyUSB0 --out cap.jsonl
raydriver analyzer tui --port /dev/ttyUSB0     # interactive monitor

# Ruida: network, USB or the built-in controller emulator
raydriver analyzer record --protocol ruida --host 192.168.1.50 --out ruida.jsonl
raydriver analyzer record --protocol ruida --usb-device /dev/ttyUSB0 --out ruida.jsonl
raydriver analyzer tui --protocol ruida --emulator

# Print a capture as a decoded listing
raydriver analyzer decode cap.jsonl

# Replay captured frames at a device, at up to Nx speed
raydriver analyzer replay cap.jsonl --to 192.168.1.50:23 --speed 10

# Man-in-the-middle: point an application at the proxy in front of
# a TCP device and record both directions
raydriver analyzer proxy --upstream 192.168.1.50:23 --out mitm.jsonl

Golden tests pin wire behavior: deterministic scenarios run against the firmware emulators, and their decoded listings are diffed against fixtures under tests/golden/ (regenerate with RAYDRIVER_REGEN_GOLDEN=1). Captures from real hardware can be dropped in as fixtures the same way, so protocol changes that alter what goes over the wire fail loudly.

Security policy

Analyzer network endpoints are hardened before any socket opens:

  • listeners bind loopback (127.0.0.1) without authentication by default;
  • non-loopback or wildcard binds require both a token and TLS — there is no override;
  • explicitly configured authentication is never dropped.

Token checks and TLS handshakes are covered by tests that drive the real sockets and assert on the outcomes.

Releases

Releasing mirrors the Raygeo flow:

  1. Configure a PyPI trusted publisher for this repository once (owner barebaric, repo raydriver, workflow release.yml, environment pypi).
  2. gh release create v0.1.0 --title "v0.1.0" --generate-notes

The Build and Publish workflow then stamps the version from the tag, builds wheels (Linux/Windows/macOS) and an sdist, publishes to PyPI via OIDC, and attaches the artifacts to the GitHub release.

Development

make venv && source .venv/bin/activate
make dev     # build + install (do this before testing)
make test    # pytest suite (all tests are Python-based)
make check   # lint + test

Usage

import asyncio
from raydriver.config import GrblSerialConfig
from raydriver.core import SessionEvent
from raydriver.grbl import GrblSession

session = GrblSession(
    config=GrblSerialConfig(port="/dev/ttyUSB0", baudrate=115200),
    dialect={
        "home_all": "$H",
        "home_axis": "$H{axis_letter}",
        "clear_alarm": "$X",
        "laser_on": "M4 S{power:.0f}",
        "laser_off": "M5",
    },
    event_callback=on_event,
)

def on_event(event: SessionEvent):
    match event:
        case SessionEvent.StateChanged():
            print("device state:", event.state.status.name)
        case SessionEvent.ConnectionStatusChanged(status=status):
            print("connection:", status)
        case SessionEvent.RawRx(line=line):
            print("<<", line)
        case SessionEvent.RawTx(line=line):
            print(">>", line)

async def main():
    await session.connect()
    print(await session.execute_interactive_command("$I"))
    await session.disconnect()

asyncio.run(main())

xTool M2

M2Session connects to the M2's WS-V2 service for state monitoring, homing, motion and control of a job already staged on the machine. It does not upload or stream G-code jobs; use xTool Studio to stage those. M2 support uses a reverse-engineered local protocol and has not yet been validated against physical hardware.

The device commonly presents a self-signed TLS certificate. Certificate validation remains enabled by default. Set tls_allow_invalid_certs only on a trusted private network if the device certificate is not trusted by the host:

import asyncio
from raydriver.core import SessionEvent
from raydriver.xtool.m2 import M2Session

async def main():
    connected = asyncio.Event()

    def on_event(event):
        if (
            isinstance(event, SessionEvent.ConnectionStatusChanged)
            and event.status == "CONNECTED"
        ):
            connected.set()

    session = M2Session(
        config={
            "host": "192.168.1.50",
            "tls_allow_invalid_certs": True,
        },
        event_callback=on_event,
    )
    await session.connect()
    await asyncio.wait_for(connected.wait(), timeout=15)
    await session.disconnect()

asyncio.run(main())

The session also exposes home, move_to, jog, start, set_hold and cancel for supported machine-control operations. connect starts the connection loop; wait for the CONNECTED connection-status event before issuing machine commands.

Metadata

Release files for raydriver 1.23.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 raydriver 1.23.0
File Size Uploaded Provenance Actions
raydriver-1.23.0.tar.gz 602.0 kB With provenance Details for raydriver-1.23.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for raydriver 1.23.0
File Actions
raydriver-1.23.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for raydriver-1.23.0-cp311-abi3-win_amd64.whl
raydriver-1.23.0-cp311-abi3-manylinux_2_34_x86_64.whl CPython 3.11 abi3 Linux glibc 2.34+ x86-64 Details for raydriver-1.23.0-cp311-abi3-manylinux_2_34_x86_64.whl
raydriver-1.23.0-cp311-abi3-manylinux_2_34_aarch64.whl CPython 3.11 abi3 Linux glibc 2.34+ ARM64 Details for raydriver-1.23.0-cp311-abi3-manylinux_2_34_aarch64.whl
raydriver-1.23.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for raydriver-1.23.0-cp311-abi3-macosx_11_0_arm64.whl
raydriver-1.23.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for raydriver-1.23.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 30.2 MB

Release files / raydriver-1.23.0.tar.gz

Download URL raydriver-1.23.0.tar.gz
Size 602.0 kB
Tags Source
SHA-256 checksum
How to use checksums
945ce0289646630145301243e3e5aec7ee0306b3f6f1e34a272d64ab1effc474
BLAKE2b-256 checksum
How to use checksums
79e92231d99055b09ec1796794592c93b40935db815806a75f330898a4efcde3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / raydriver-1.23.0-cp311-abi3-win_amd64.whl

Download URL raydriver-1.23.0-cp311-abi3-win_amd64.whl
Size 5.5 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b67297d37d2d1dec4452b0912c51bb6ff6ca0b7dd2cc1ac7cd36f6b1cc6a0930
BLAKE2b-256 checksum
How to use checksums
c38b3414e5de382ed9902bc334f4b810eb7926ba08a4f1a8b7dec693018e09df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / raydriver-1.23.0-cp311-abi3-manylinux_2_34_x86_64.whl

Download URL raydriver-1.23.0-cp311-abi3-manylinux_2_34_x86_64.whl
Size 6.5 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
fcc21bc7415de25b8d64a6691a3eb1f0c882d8aff056ac319ecfcabf10063425
BLAKE2b-256 checksum
How to use checksums
f979b561634b4cc2e49d37ab836882e509b92348c8659c5930c3527ee3337f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / raydriver-1.23.0-cp311-abi3-manylinux_2_34_aarch64.whl

Download URL raydriver-1.23.0-cp311-abi3-manylinux_2_34_aarch64.whl
Size 6.6 MB
Tags CPython 3.11 Linux glibc 2.34+ ARM64 abi3
SHA-256 checksum
How to use checksums
251591184cc402a0232bfc4bbbfd99ff9be0bb8bb05c7fe5ee989881ede9de9e
BLAKE2b-256 checksum
How to use checksums
95d87106300ea8f8c6ce226ed556f698c7f590a4b5b516220e968b45c54b91eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / raydriver-1.23.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL raydriver-1.23.0-cp311-abi3-macosx_11_0_arm64.whl
Size 5.4 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a177b95b00a1555a711a47b5c1185b02896390539520d863274537ec2ee658ea
BLAKE2b-256 checksum
How to use checksums
c00ff98a7114d1e436139e515f0f254de51bbe18455e102dc3773fa3a9fa823c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / raydriver-1.23.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL raydriver-1.23.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 5.7 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2e342ed66f9129c93a547576788f21cac5ac4de08788886212398b0f95053e88
BLAKE2b-256 checksum
How to use checksums
df43a9b2737a656ec884c139eedb0ddb0f0a967cc36bfe9582fbb41cd95d4aca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Security for raydriver 1.23.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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for raydriver-1.23.0.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 Nov 26, 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.

Release history Release notifications | RSS feed

This release

1.23.0 This release

6 release files Full provenance

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