Skip to main content

Synchronous Python client for the gomc-rest API

Project description

gomc-rest-client

日本語版 README

Python 3.10+ client library for the latest gomc-rest HTTP API.

This package wraps the synchronous REST endpoints exposed by gomc-rest for Mitsubishi PLC read, write, and remote-control operations using only the Python standard library, and converts API error responses into typed Python exceptions.

About gomc-rest-client

This package is a dedicated client library for gomc-rest. It is intended for users who already use gomc-rest, or who want to expose Mitsubishi PLC operations through the gomc-rest HTTP API.

This library does not communicate with PLCs directly. If you need the server, API surface, or gomc-rest itself, see the upstream project:

Install

uv add gomc-rest-client

With pip:

pip install gomc-rest-client

PyPI project page:

For offline environments, install from a prebuilt wheel distributed inside your network:

pip install dist/gomc_rest_client-*.whl

This package has no runtime dependencies outside the Python standard library, so wheel-based offline installation is straightforward.

Development tasks currently use dev dependencies such as PyYAML, pytest, ruff, and ty, but they are not required at runtime.

To set up the development environment:

uv sync --group dev

To build distributable artifacts before taking them into an offline environment:

uv build

Usage

from gomc_rest_client import (
    MINIMUM_SUPPORTED_GOMC_REST_VERSION,
    GomcRestBusyError,
    GomcRestPLCProtocolError,
    PLCClient,
)

with PLCClient("http://192.168.0.1:8080") as plc:
    health = plc.health()
    metrics = plc.metrics()
    info = plc.info()
    version = plc.version()
    is_supported = plc.is_supported_version()
    is_compatible = plc.is_version_compatible(MINIMUM_SUPPORTED_GOMC_REST_VERSION)
    values = plc.read("D100", 3)
    bits = plc.read("M0", 4)
    dwords = plc.read("D100", 2, dword=True)
    signed = plc.read("D100", 3, sint=True)

    plc.write("D100", [10, 20, 30])
    plc.write("M0", [True, False])
    plc.write("D100", [-1, -32768, 32767], sint=True)
    random_values = plc.random_read(words=["D100", "D200"], dwords=["D300"], bits=["D100.1", "M0"])
    plc.random_write_pairs(
        words=[("D100", 10)],
        dwords=[("D300", 65536)],
        bits=[("M0", True)],
    )

    try:
        plc.remote_run(clear=0, force=False)
    except GomcRestBusyError:
        pass
    except GomcRestPLCProtocolError as exc:
        print(exc.end_code, exc.message)

If you want to write multiple non-contiguous addresses, random_write_pairs() accepts (addr, value) pairs directly.

plc.random_write_pairs(
    words=[("D100", 10), ("D200", 20)],
    dwords=[("D300", 65536), ("D302", 123456)],
    bits=[("M0", True), ("M10", False)],
)

If you prefer the server payload shape directly, random_write() still accepts { "addr": "...", "value": ... } dictionaries.

plc.random_write(
    words=[
        {"addr": "D100", "value": 10},
        {"addr": "D200", "value": 20},
    ],
    dwords=[
        {"addr": "D300", "value": 65536},
        {"addr": "D302", "value": 123456},
    ],
    bits=[
        {"addr": "M0", "value": True},
        {"addr": "M10", "value": False},
    ],
)

random_read() takes address-string lists. bits accepts up to 255 addresses total: word-device bit access (e.g. D100.1) and bit devices (e.g. M0). Bit devices are capped at 16 per request by the server; word-device bit access has no such limit.

The return value is a dictionary with words, dwords, and bits lists in request order.

result = plc.random_read(words=["D100", "D200"], dwords=["D300"], bits=["D100.1", "M0"])
# {"words": [100, 200], "dwords": [65536], "bits": [True, False]}

is_supported_version() and is_version_compatible() treat dev builds as compatible by default so local gomc-rest main builds can pass version checks during development.

Supported gomc-rest versions

This client supports gomc-rest v1.3.0 and later.

Servers older than v1.3.0 are not supported because this client relies on the v1.3.0 bits support in /random-read and the timeout_count field added to /metrics in that release.

This client expects the server to expose /version, /info, /metrics, /random-read, and /random-write.

If you need to verify the support policy at runtime, call plc.is_supported_version() or compare against MINIMUM_SUPPORTED_GOMC_REST_VERSION.

API coverage

  • GET /version
  • GET /info
  • GET /metrics
  • GET /health
  • GET /read
  • POST /write
  • POST /random-read
  • POST /random-write
  • POST /remote/run
  • POST /remote/stop
  • POST /remote/pause
  • POST /remote/latch-clear
  • POST /remote/reset

Remote-control endpoints require the gomc-rest server to start with -enable-remote.

Development

Run checks with uv:

uv run pytest
uv run ruff check .
uv run ty check
uv build

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

gomc_rest_client-0.9.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gomc_rest_client-0.9.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file gomc_rest_client-0.9.0.tar.gz.

File metadata

  • Download URL: gomc_rest_client-0.9.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gomc_rest_client-0.9.0.tar.gz
Algorithm Hash digest
SHA256 72dcece724eb6f1cfd522194b52e7b4d3b2814e23d807bacec305376d038e5f5
MD5 4650643dc1576d03d2b168ab3ec6c7a1
BLAKE2b-256 4f876fc9a5330f440ffd1f6878cb7125342ae6415587a580f0dd7335815d01f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest_client-0.9.0.tar.gz:

Publisher: workflow.yml on Moge800/gomc_rest_client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gomc_rest_client-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gomc_rest_client-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 893cc553c6ea3889f934f49ba59b46e3af0f609801ab0d259f88d2a4097cd30f
MD5 29a1ea6954ef34df78c16a1f46f38196
BLAKE2b-256 b4ca2f411d754c7648586b915fae241efa6f8d9bf97e475f5f4a639994c83d07

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest_client-0.9.0-py3-none-any.whl:

Publisher: workflow.yml on Moge800/gomc_rest_client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page