Skip to main content

gomc-rest (Python)

English / 日本語

A Python library for talking to Mitsubishi PLCs. Read and write PLC devices over the MC protocol (3E/4E frames) — the protocol is handled for you by a bundled gomc-rest server that the package auto-launches, so you never have to start or distribute an executable yourself.

Bonus — expose a REST API. Enable server_mode to make the bundled server's REST API reachable from other apps on your network (a GUI, another machine, another language); and connect() talks to a gomc-rest server that is already running elsewhere. See Access control.

Under the hood the HTTP layer is provided by gomc-rest-client; this package adds the bundled binary and its process lifecycle.

your Python process
└─ gomc_rest.launch()
     ├─ spawns the bundled gomc-rest on a free loopback port  ── MC protocol ──▶ PLC
     └─ returns a Server that provides a PLCClient pointed at it

Install

pip install gomc-rest

Usage

import gomc_rest

with gomc_rest.launch(plc_host="192.168.0.1") as plc:
    values = plc.read("D100", 3)
    plc.write("D100", [10, 20, 30])
# the bundled server is stopped automatically on exit

launch() returns a Server; using it as a context manager yields a PLCClient (see gomc-rest-client for the full read/write/remote API) and stops the server on exit. Without with, the server is stopped at interpreter exit.

Pass server flags through extra_args:

with gomc_rest.launch(plc_host="192.168.0.1", extra_args=["-enable-remote"]) as plc:
    plc.remote_run()

Client mode (connect to an existing server)

To talk to a gomc-rest server that is already running elsewhere — a shared instance, another machine, or one you launched with server_mode=True — use connect() instead of starting the bundled binary:

with gomc_rest.connect("http://192.168.0.1:8080", token="...") as plc:
    plc.read("D100", 3)

Both launch() and connect() hand you the same PLCClient, so one package covers "bundle and run the server" and "just be a client".

connect() needs no bundled binary, so it works even on platforms without a prebuilt wheel (Windows arm64, glibc < 2.34, macOS < 12): there pip install gomc-rest installs from the sdist, and only launch() is unavailable (it raises a clear error).

Access control

Two independent layers protect the server, both on by default:

  1. Per-launch bearer token. A random token is generated each launch and required by the server, so even another process on the same host that discovers the port cannot call the API. It is set automatically on the returned client and exposed as server.token. Pass an explicit token= to share with another app, or token="" to disable auth (closed-network use).
  2. Loopback binding. By default the server binds to 127.0.0.1, so no other host can reach it.

Set server_mode=True to bind all interfaces so other apps on the network (e.g. gomc-rest-gui, curl from another machine) can call it — give them server.token:

server = gomc_rest.launch(plc_host="192.168.0.1", server_mode=True)
print(server.base_url)   # other apps connect to http://<this-host>:<port>
print(server.token)      # ...with this bearer token
try:
    server.client.read("D100", 3)
finally:
    server.close()

The server has no TLS — only enable server_mode on a trusted network.

Threat model. The token is passed to the server via the GOMCR_TOKEN environment variable (not the command line), so it does not appear in the process list. It protects against other hosts and other OS users. It does not protect against another process running as the same OS user, which can read the server's environment (e.g. /proc/<pid>/environ); the OS user boundary is the trust boundary here.

Versions

This package bundles a pinned gomc-rest binary (currently v1.6.0, set in GOMC_REST_VERSION) that must satisfy gomc-rest-client's MINIMUM_SUPPORTED_GOMC_REST_VERSION; launch() verifies this on startup. The gomc-rest-client dependency is capped (>=0.10.0,<0.11) so a future client that raises its minimum server version can't be installed without also bumping the bundled binary.

Development

Release procedure and bundled-binary maintenance are documented in RELEASING.md.

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-0.2.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distributions

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

gomc_rest-0.2.0-py3-none-win_amd64.whl (6.0 MB view details)

Uploaded Python 3Windows x86-64

gomc_rest-0.2.0-py3-none-manylinux_2_34_x86_64.whl (6.0 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

gomc_rest-0.2.0-py3-none-manylinux2014_aarch64.whl (5.5 MB view details)

Uploaded Python 3

gomc_rest-0.2.0-py3-none-macosx_12_0_x86_64.whl (6.1 MB view details)

Uploaded Python 3macOS 12.0+ x86-64

gomc_rest-0.2.0-py3-none-macosx_12_0_arm64.whl (5.7 MB view details)

Uploaded Python 3macOS 12.0+ ARM64

File details

Details for the file gomc_rest-0.2.0.tar.gz.

File metadata

  • Download URL: gomc_rest-0.2.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for gomc_rest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 09cd78910e54e3c28ffa0f8bac2958192fb99c351f14731b95c2e6e77ae6a4a9
MD5 3f4f92b1b55fc2c54220628b5610a183
BLAKE2b-256 0d1537ab427d2e7bfb057de634ac99389c4ee478bb9d90167b1b7251ba534ec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest-0.2.0.tar.gz:

Publisher: release.yml on Moge800/gomc_rest_python

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-0.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: gomc_rest-0.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for gomc_rest-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c19843932ca4359fd27fce47259e5af2563a74f9e4f2713c1d071d4eb20efca1
MD5 48d4f75a1fc2b163e945cecfecbd0266
BLAKE2b-256 6f85f92e3c1f4c0cf0f836c736bc8f9f01c273d96ae1eb1257439fe37ca037e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest-0.2.0-py3-none-win_amd64.whl:

Publisher: release.yml on Moge800/gomc_rest_python

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-0.2.0-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for gomc_rest-0.2.0-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e77d00a85d4cca359c7d9c103c7668dbd9908cd861ef07a066ecd0e730759f3d
MD5 8b9023fd60888f2477ef7651606826db
BLAKE2b-256 f5e49df3618f215cc3804d4ee982df9cde667de7bb0e5e7bb3e78652772fc005

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest-0.2.0-py3-none-manylinux_2_34_x86_64.whl:

Publisher: release.yml on Moge800/gomc_rest_python

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-0.2.0-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gomc_rest-0.2.0-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e5cff0830f35c927d4debc6c1169313a7c12d47fd2d9c6c8ac1d6cb98aad0c96
MD5 06eeed76b51428bca0aca7ebbd83a24c
BLAKE2b-256 6b0b17b95ba8c3e95084d20a6630a821d61540c3e033411bbfc3da7270d282ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest-0.2.0-py3-none-manylinux2014_aarch64.whl:

Publisher: release.yml on Moge800/gomc_rest_python

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-0.2.0-py3-none-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for gomc_rest-0.2.0-py3-none-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 3a719e05fcf2ef1203bafee445fdd8be18c00d96e88f39818e4277b55bb977a3
MD5 75d94421145e05e8726a8ad7b3ce2aa3
BLAKE2b-256 31f92efdd87b90b0e9e6fe147058e414b303536cef8ea6f6f05c9509bae75c56

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest-0.2.0-py3-none-macosx_12_0_x86_64.whl:

Publisher: release.yml on Moge800/gomc_rest_python

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-0.2.0-py3-none-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for gomc_rest-0.2.0-py3-none-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 96d97075857b1b5d0553ae90144e07fe75d5efd897c0de668c14503c7dad0361
MD5 1a048383d1957dee071a356e388ffa27
BLAKE2b-256 1065238eca7174b67da5ca38dd511721b84541338e78cebc2fcbdfcabb8eb829

See more details on using hashes here.

Provenance

The following attestation bundles were made for gomc_rest-0.2.0-py3-none-macosx_12_0_arm64.whl:

Publisher: release.yml on Moge800/gomc_rest_python

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

Release history Release notifications | RSS feed

This release

0.2.0 This release

6 files

0.1.2

4 files

0.1.1

4 files

0.1.0

4 files

Supported by

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