Skip to main content

venusrpc

Fast HTTP-based Python bridge to the Hamilton Venus HSL runtime.

venusrpc lets you drive a Hamilton STAR liquid handler from Python by calling HSL submethods over a loopback HTTP connection to the Venus run-time environment (HxRun.exe). The HSL host script that runs inside Venus is shipped with the package.

Credit

venusrpc is a separate implementation of the idea pioneered by PyVenus by SNIPR Biome — driving Venus from Python via an HSL host script. The codegen approach (parsing .lay / .smt / .hsi to emit typed Python wrappers) and the HSL helpers shipped here are directly inspired by their work. venusrpc swaps PyVenus's file-polling IPC for a loopback HTTP socket so per-call latency drops from ~150–300 ms to ~1–5 ms.

Status

Alpha. APIs may change between minor versions. Requires Windows with Hamilton Venus installed, for driving an instrument and for codegen (Venus's converter reads the binary .lay/.smt files). Tested with Venus 4.5 and Venus 6.

HSL libraries venusrpc needs from Venus's Library folder (C:\Program Files (x86)\HAMILTON\Library):

Library Include Needed for
HSLHttp HSLHttp\HSLHttp.hsl always: the HTTP transport to Python
HSLStrLib HSLStrLib.hsl always: string handling in the host script
HSLLabwrAccess HSLLabwrAccess\HSLLabwrAccess.hsl only Labware pose nudges; include it yourself via con.execute(definitions=...)

If one is missing, Connection fails at startup with Venus's cannot open include file error naming it.

Install

pip install venusrpc

Quickstart

venusrpc init my_method && cd my_method
# copy your deck to lay/deck.lay (+ .res) and submethod libraries to smt/
venusrpc generate

venusrpc generate turns the deck layout and submethod libraries into typed Python wrappers under venus_resources/. A method then reads like this:

from venusrpc import Connection, Device, Sequence
from venus_resources.__layout__deck import Deck
from venus_resources.__smt__channels1ml_8 import Channels1ml_8
from venus_resources.__smt__ml_star import Ml_star

with Connection(layout_file=Deck.file, simulation=True) as con:
    star = Device.from_existing(con)
    channels = Channels1ml_8(con)
    tips = Sequence(con, Deck.Sequences.Tips_50ul, deck_sequence=True)
    source = Sequence(con, Deck.Sequences.Source_tubes, deck_sequence=True)
    target = Sequence(con, Deck.Sequences.Target_plate, deck_sequence=True)

    Ml_star(con).initialize(star)
    channels.tip_pickup(ML_STAR=star, positions=tips)
    channels.aspirate(
        ML_STAR=star, positions=source, volume=10,
        liquid_class="Tip_50ulFilter_Water_DispenseSurface_Empty",
    )
    channels.dispense(ML_STAR=star, positions=target, volume=10)
    channels.tip_eject(ML_STAR=star, positions=tips, default_waste=1)

How it works

Python (HTTP server)                   Venus (HTTP client)
─────────────────                      ─────────────────
HTTPServer on 127.0.0.1:0  ◄── GET ─── HxRun.exe -t venusrpc_host.hsl
write venusrpc.port
─── HTTP response (JSON) ─────────►   __EvalExpr__()
◄── next GET with result    ──────
... loop ...

Python is the server because it is the only side that knows its ephemeral port. The HSL host reads venusrpc.port from the same directory as the host script and connects back.

Sequence pull semantics

Sequence.pull() (called automatically at the end of every generated SMT wrapper) returns only the cursor — current and end. Labware and position entries are not round-tripped: Python pushed them, Venus's increment_sequence only walks the cursor along them, so re-serializing the arrays on every call wastes bandwidth and exposes an HSL sequence quirk where each push() appends to GetTotal() without truncating, so the JSON payload doubles per call (~30 bytes → MB after a dozen iterations, killing HxRun via stack/memory pressure).

Call Returns Use
seq.pull() current, end default; safe for any SMT op
seq.pull_full() current, end, labware, position rare: Venus populated the sequence itself (e.g. a barcode scan SMT)
seq.pull_with_xyz() + per-position xyz/angle inspecting taught coordinates

Automatic sequence counting still works — Venus's increment_sequence advances GetCurrentPosition(), which pull() reads back. The only thing you lose is the ability to see labware/position changes Venus made server-side, which no current SMT does. If you ever write one that mutates a sequence, call pull_full() at that one site.

Codegen

venusrpc.Codegen parses Venus deck layouts (.lay), submethod libraries (.smt + .hsi), labware definitions (.rck/.tml/.lid + linked .ctr), and (optionally) the Hamilton liquid class Access DB. It emits typed Python wrappers into ./venus_resources/ that import from venusrpc.

from venusrpc import Codegen
Codegen.read_layout("example_layout.lay")
Codegen.read_submethods("./smt")
Codegen.read_liquid_classes()  # Windows + pyodbc
Codegen.read_labware("example_layout.lay")  # vendors + parses referenced labware

read_labware resolves every placed labware in the .lay to its definition file, copies (vendors) the referenced files under resources/labware/ so the build is repo-local, and emits __labware__.py — one top-level class per definition, each subclassing Rack, Carrier, or Lid (from venusrpc) so its kind is explicit. Every definition carries footprint length/width/ height; Racks additionally expose rows/columns/pitch, well depth/max_volume/volume_eqn, and the segments_x/segments_y profile (with width_at_x(h)/width_at_y(h) helpers).

Placed instances live on the deck layout class, not in __labware__: when labware codegen is enabled, the deck class gains an Instances nested class of LabwareInstance objects — each carrying the exact placed name (.name, e.g. "Cos_96_HalfArea_PR_Source") and its shared .definition. Other attributes proxy to the definition, so no data is duplicated:

inst = Ngsstarv_deck.Instances.Cos_96_HalfArea_PR_Source
inst.name        # "Cos_96_HalfArea_PR_Source"  (exact deck Id)
inst.definition  # labware.Cos_96_HalfArea       (shared Rack subclass)
inst.model       # "Cos_96_HalfArea"             (proxied; the .rck stem)
inst.length      # 127.0                          (proxied)

The definition's own type name is model (the placed name owns name).

Config-driven codegen

Instead of calling Codegen by hand on every change, declare a [tool.venusrpc] block in pyproject.toml (or a standalone venusrpc.toml in the project root) and use the venusrpc CLI.

# pyproject.toml
[tool.venusrpc]
layouts = ["lay/my_deck.lay"]   # str or list; paths relative to this file
submethods_dir = "smt"                 # default: ./smt
output_dir = "venus_resources"         # default: ./venus_resources

# Opt-in runtime guard. Set to `true` (strict, raises StaleResourcesError),
# `"warn"` (issue UserWarning), or omit/false to skip. See verify_resources().
verify_on_import = false

[tool.venusrpc.liquid_classes]
enabled = true                         # set false to skip the DB scan
include_1ml_channels = true
include_5ml_channels = false
include_96head = true
include_384head = false
include_washstations = false
include_default = true
include_custom = true
database = 'C:\Program Files (x86)\HAMILTON\Config\ML_STARLiquids.mdb'

[tool.venusrpc.labware]
enabled = true                         # set false to skip labware codegen
# Source root the deck's relative labware paths resolve against. Referenced
# definitions are vendored into vendor_dir (repo-local) and parsed from there.
base = 'C:\Program Files (x86)\HAMILTON\LabWare'
vendor_dir = "resources/labware"       # default: resources/labware (rel. to this file)

Commands (auto-detect config in cwd; override with --config <file>):

Command Behavior
venusrpc generate Regenerate wrappers whose source hash differs. Up-to-date files print Up-to-date: <path>. Regenerated print Generated: <path>.
venusrpc generate --force Regenerate every wrapper regardless of hash. Use after editing the codegen template.
venusrpc check Verify every generated file's stored hash matches its source. Exits 0 if clean, 2 if any entry is stale or missing — suitable for CI / pre-commit.
venusrpc check --warn Same diagnostic, but exits 0.

Opt-in runtime guard

For an early failure when a teammate forgets to run venusrpc generate, import the helper at the top of your driver script:

from venusrpc import verify_resources
verify_resources()   # honors `verify_on_import` from config

# or force a mode regardless of config:
verify_resources(mode="strict")  # raises StaleResourcesError
verify_resources(mode="warn")    # emits UserWarning

mode="auto" (default) reads verify_on_import from the resolved config:

verify_on_import value Effect
true strict — raises StaleResourcesError listing every stale entry
"warn" issues a UserWarning, returns the stale list
false / unset no-op

Differences from PyVenus

PyVenus venusrpc
Transport File polling (100 ms / 200 ms loops) HTTP over loopback, blocking I/O
Per-call floor latency ~150–300 ms ~1–5 ms
Connection.execute() returns JSON string parsed dict
Re-parsing call sites required not needed
Liquid class DB driver hard dependency on pyodbc hard dependency on pyodbc
Python 3.8+ 3.10+

Development

uv sync --extra dev
uv run pytest

License

LGPL-3.0-or-later. See LICENSE and COPYING.

AI disclosure

Most of this code was written with Claude Code, under human direction and review. Treat it as you would any alpha library: read what you run, and try new methods in simulation first.

Metadata

Release files for venusrpc 0.1.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 venusrpc 0.1.0
File Size Uploaded Provenance Actions
venusrpc-0.1.0.tar.gz 133.6 kB Without provenance Details for venusrpc-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for venusrpc 0.1.0
File Interpreter ABI Platform Actions
venusrpc-0.1.0-py3-none-any.whl Python 3 none any Details for venusrpc-0.1.0-py3-none-any.whl

Total release size: 202.4 kB

Release files / venusrpc-0.1.0.tar.gz

Download URL venusrpc-0.1.0.tar.gz
Size 133.6 kB
Tags Source
SHA-256 checksum
How to use checksums
90d49f1665ce318052efa76ca178bcbdc925ae34aebb3b316e84338af35b02e1
BLAKE2b-256 checksum
How to use checksums
f41058130d8a50c5883770a62285cabb20174ae431d44eda91eb82424af2e704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 / venusrpc-0.1.0-py3-none-any.whl

Download URL venusrpc-0.1.0-py3-none-any.whl
Size 68.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d8c1969b48250ba83fe2d3f31e4fee3fe097457801cb7b855f95451aa0d7fa1
BLAKE2b-256 checksum
How to use checksums
b5508f9dcff9e22ef6da1451afefcfa783f7b82203b6d888a171f22c17b2b311
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 venusrpc 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No 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