hid based usb relay package
Project description
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 interfacehid-usb-relay-gui— launch the Dear PyGui desktop UIhid-usb-relay-api— start the FastAPI server on0.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 devicesstate/status— read the current relay statecontrol— set a relay state toonoroff
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 informationGET /health— health check and connected device count
Relay endpoints:
GET /api/v1/devices— list connected devicesGET /api/v1/relay/control?relay_number=1&relay_state=on— change relay statePOST /api/v1/relay/control— change relay state with JSON payloadGET /api/v1/relay/state?relay_number=1— read relay statePOST /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.
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, andhid_usb_relay.guidirectly.
Source manual
For more documentation, see the source manual.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hid_usb_relay-26.1.2.tar.gz.
File metadata
- Download URL: hid_usb_relay-26.1.2.tar.gz
- Upload date:
- Size: 233.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b64eb1ba4adfef915b4ae5197643ed5c6888c2d87a469bbea2032fb282e0cef
|
|
| MD5 |
8f481e639ca8a9c59c24927a20ea7990
|
|
| BLAKE2b-256 |
e87bc5866eec12c2cf8342b529e746ea14b3319fbe596b47b52e1de02dc45847
|
File details
Details for the file hid_usb_relay-26.1.2-py3-none-any.whl.
File metadata
- Download URL: hid_usb_relay-26.1.2-py3-none-any.whl
- Upload date:
- Size: 227.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
019caf9e930c4289203ab42c233f23f494a38ea004d32deb2927c1800f736b0b
|
|
| MD5 |
781134cb8590512e67bf336f9a0731f7
|
|
| BLAKE2b-256 |
3544e444394f1e0538d11d557417c072431f9dcdc6a5c7f2c7770fe691219fb8
|