Talk to Mitsubishi PLCs from Python over the MC protocol via a bundled, auto-launched gomc-rest server — with optional REST API exposure.
Project description
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 (macOS, Windows arm64, glibc < 2.34): 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:
- 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 explicittoken=to share with another app, ortoken=""to disable auth (closed-network use). - 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.4.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.
Releasing / bundled binaries
The bundled server version is pinned in GOMC_REST_VERSION. Binaries are not
committed to git; they are fetched from the matching gomc-rest GitHub release.
- Locally:
python scripts/vendor_binaries.pydownloads all three binaries intosrc/gomc_rest/binaries/, verifying each against the trusted SHA-256 values committed inchecksums/<version>.sha256. - On a
v*tag,.github/workflows/release.ymlbuilds one platform-specific wheel per OS (each bundling only its matching binary) and publishes to PyPI via trusted publishing. The release job verifies the tag equalsproject.version;workflow_dispatchbuilds wheels for verification only and never publishes.
To cut a release:
- To change the bundled server, edit
GOMC_REST_VERSION(keep it within the range accepted by the pinnedgomc-rest-client) and add a matchingchecksums/<version>.sha256with the trusted SHA-256 of each asset. If the new binaries change their glibc requirement, update theplattags inrelease.ymlaccordingly. - Bump the package version in both
pyproject.toml(project.version) andsrc/gomc_rest/__init__.py(__version__) — they must match. - Tag that exact version, e.g.
git tag v0.2.0 && git push origin v0.2.0(the tag must equalproject.versionor the release job fails).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 gomc_rest-0.1.1.tar.gz.
File metadata
- Download URL: gomc_rest-0.1.1.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9937213e57adc82f421874973dd57d93476d1b140e9e80e9b361603a8fdd1782
|
|
| MD5 |
161d5997dfe6fdcbf0d40a1f9a12f7c7
|
|
| BLAKE2b-256 |
15c1ec8b77514cfa7609d3fc469c2165c000cade858c6e4259750473d9519af4
|
Provenance
The following attestation bundles were made for gomc_rest-0.1.1.tar.gz:
Publisher:
release.yml on Moge800/gomc_rest_python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gomc_rest-0.1.1.tar.gz -
Subject digest:
9937213e57adc82f421874973dd57d93476d1b140e9e80e9b361603a8fdd1782 - Sigstore transparency entry: 2084663566
- Sigstore integration time:
-
Permalink:
Moge800/gomc_rest_python@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Moge800
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gomc_rest-0.1.1-py3-none-win_amd64.whl.
File metadata
- Download URL: gomc_rest-0.1.1-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.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a69da1535fc3ff897b42022586e961b4f6f56ac5a93a9951bad74b4487b02e3c
|
|
| MD5 |
0c634c85b5fdb8c9375aa04a9db03173
|
|
| BLAKE2b-256 |
d326e823e16753627d9448baf62147d0d4305d4b03c42919bae0a319b38e4652
|
Provenance
The following attestation bundles were made for gomc_rest-0.1.1-py3-none-win_amd64.whl:
Publisher:
release.yml on Moge800/gomc_rest_python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gomc_rest-0.1.1-py3-none-win_amd64.whl -
Subject digest:
a69da1535fc3ff897b42022586e961b4f6f56ac5a93a9951bad74b4487b02e3c - Sigstore transparency entry: 2084663616
- Sigstore integration time:
-
Permalink:
Moge800/gomc_rest_python@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Moge800
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gomc_rest-0.1.1-py3-none-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: gomc_rest-0.1.1-py3-none-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 6.0 MB
- Tags: Python 3, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df831b73dd4ca0ab86df63ca95ac4400bc3e9c3adb7a45274c3a4c8b20b5ee22
|
|
| MD5 |
dafd5f1d9f826558ad03eb9f5434221b
|
|
| BLAKE2b-256 |
15094475399d69449a26d9912e74a0fdc090bd1228191c37429b863459e00798
|
Provenance
The following attestation bundles were made for gomc_rest-0.1.1-py3-none-manylinux_2_34_x86_64.whl:
Publisher:
release.yml on Moge800/gomc_rest_python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gomc_rest-0.1.1-py3-none-manylinux_2_34_x86_64.whl -
Subject digest:
df831b73dd4ca0ab86df63ca95ac4400bc3e9c3adb7a45274c3a4c8b20b5ee22 - Sigstore transparency entry: 2084663588
- Sigstore integration time:
-
Permalink:
Moge800/gomc_rest_python@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Moge800
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gomc_rest-0.1.1-py3-none-manylinux2014_aarch64.whl.
File metadata
- Download URL: gomc_rest-0.1.1-py3-none-manylinux2014_aarch64.whl
- Upload date:
- Size: 5.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14573f2d8a448185188929309b314cf5c0d045bcde76273619d4950604fa0347
|
|
| MD5 |
67887cd46988b1c837e08fe3ee0eec05
|
|
| BLAKE2b-256 |
679194ff324f9aab7f0ad4d75795c01de036bd3b268c61a6189d62d653bcee44
|
Provenance
The following attestation bundles were made for gomc_rest-0.1.1-py3-none-manylinux2014_aarch64.whl:
Publisher:
release.yml on Moge800/gomc_rest_python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gomc_rest-0.1.1-py3-none-manylinux2014_aarch64.whl -
Subject digest:
14573f2d8a448185188929309b314cf5c0d045bcde76273619d4950604fa0347 - Sigstore transparency entry: 2084663657
- Sigstore integration time:
-
Permalink:
Moge800/gomc_rest_python@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Moge800
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d99e60803be0617b8d4188cac62eddc6014b17a5 -
Trigger Event:
push
-
Statement type: