Skip to main content

hid_usb_relay

A Python package for controlling HID USB relay devices with an API, CLI, or desktop GUI.

Installation

Install from the repository root:

pip install hid-usb-relay

Command line entry points

Once installed, use one of the provided console scripts:

  • hid-usb-relay-cli — run the command-line relay interface
  • hid-usb-relay-gui — launch the Dear PyGui desktop UI
  • hid-usb-relay-api — start the FastAPI server on 0.0.0.0:9400

CLI usage

hid-usb-relay-cli devices
hid-usb-relay-cli state 1
hid-usb-relay-cli status all
hid-usb-relay-cli control 1 on
hid-usb-relay-cli control all off

The CLI commands are:

  • devices — list connected relay devices
  • state / status — read the current relay state
  • control — set a relay state to on or off

Optional device selection is supported with --relay-id:

hid-usb-relay-cli control 1 on --relay-id DEVICE_ID

API usage

Start the API server:

hid-usb-relay-api

The server listens by default on 0.0.0.0:9400.

API endpoints

Root endpoints:

  • GET / — API information
  • GET /health — health check and connected device count

Relay endpoints:

  • GET /api/v1/devices — list connected devices
  • GET /api/v1/relay/control?relay_number=1&relay_state=on — change relay state
  • POST /api/v1/relay/control — change relay state with JSON payload
  • GET /api/v1/relay/state?relay_number=1 — read relay state
  • POST /api/v1/relay/state — read relay state with JSON payload

Example requests

curl "http://127.0.0.1:9400/health"

curl "http://127.0.0.1:9400/api/v1/devices"

curl "http://127.0.0.1:9400/api/v1/relay/control?relay_number=1&relay_state=on"

curl -X POST "http://127.0.0.1:9400/api/v1/relay/control" \
  -H "Content-Type: application/json" \
  -d '{"relay_number":"1","relay_state":"off"}'

curl "http://127.0.0.1:9400/api/v1/relay/state?relay_number=1"

curl -X POST "http://127.0.0.1:9400/api/v1/relay/state" \
  -H "Content-Type: application/json" \
  -d '{"relay_number":"1"}'

GUI usage

Run the desktop application:

hid-usb-relay-gui

This opens a simple Dear PyGui window for scanning devices, selecting a relay, and toggling relay state.

hid-usb-relay-gui

Python usage

Import the package in your own Python code:

from hid_usb_relay.usb_relay import USBRelayDevice, RelayState, RelayError, RelayService, enumerate_devices

# List devices
print(enumerate_devices())

# Read relay state
service = RelayService()
result = service.get_state(None, "1")
print(result.relay_state)

# Set relay state
result = service.set_and_get_relay_state(None, "1", "on")
print(result.relay_state)

Notes

  • The package uses platform-specific executables from src/hid_usb_relay/hid_usb_relay_bin.
  • If you do not install the console scripts, you can still import and use hid_usb_relay.api, hid_usb_relay.cli, and hid_usb_relay.gui directly.

Source manual

For more documentation, see the source manual.

Metadata

Release files for hid-usb-relay 26.1.3

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

Source distribution (sdist)

Source distribution for hid-usb-relay 26.1.3
File Size Uploaded Provenance Actions
hid_usb_relay-26.1.3.tar.gz 236.3 kB Without provenance Details for hid_usb_relay-26.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hid-usb-relay 26.1.3
File Interpreter ABI Platform Actions
hid_usb_relay-26.1.3-py3-none-any.whl Python 3 none any Details for hid_usb_relay-26.1.3-py3-none-any.whl

Total release size: 464.0 kB

Release files / hid_usb_relay-26.1.3.tar.gz

Download URL hid_usb_relay-26.1.3.tar.gz
Size 236.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d62e42f650f42f45d7695b805a354e20df8182cd6baa7b8a267950c0afd64d8a
BLAKE2b-256 checksum
How to use checksums
990baf4ddbaaaa4fcea9adf5a978f050415c1926a8d817e096fcf28d22f99d00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / hid_usb_relay-26.1.3-py3-none-any.whl

Download URL hid_usb_relay-26.1.3-py3-none-any.whl
Size 227.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72d7f20a66fd0872c19862f9aee888709058b789fd4b1ecbbaa5a8d0c1dd0d23
BLAKE2b-256 checksum
How to use checksums
923604b7fec48320fa723e763d7d9fcc6b82f19c05a8647ae9f4b5029322b442
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for hid-usb-relay 26.1.3

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