cmd_op — Python SDK
A thin Python SDK for the cmd_op resident pipe. It does one thing: forward a cmd_op command to a running resident over its named pipe and hand back the response — no per-command process spawn, so a loop of edits is ~hundreds of times faster than shelling out to the CLI per command.
"Thin" is the point: there is no second vocabulary to learn. A command is the
same dict you'd put in a cmd_op batch list; the SDK just carries it over the
pipe. Anything a doc.set_cell(...) / doc.add_paragraph(...) method would do is
fully supported — you just spell it doc.send({"command": "set", ...}), with
the exact same effect. One uniform verb instead of dozens of per-element named
methods: same power, nothing extra to memorize, and new cmd_op features work
the day they ship without an SDK update.
The cmd_op CLI (auto-installed if missing)
pip install cmd-op-sdk installs only this SDK (the Python library); the
real work is done by the cmd_op binary. You don't have to install it
yourself — if cmd_op isn't found on your PATH (or in the default install
location), the SDK provisions it on first use: it runs cmd_op's official
installer (install.sh on Linux, install.ps1 on Windows), fetched
straight from the repository. A one-line notice is
printed before it installs — it never does so silently. Pass auto_install=False
to open()/create() to disable this and require a pre-installed CLI instead.
To install the CLI ahead of time (or to control where it lands):
python -m cmd_op install # runs cmd_op's official installer
# …or directly:
curl -fsSL https://raw.githubusercontent.com/karlmoriaty/office-command-operate/main/install.sh | bash
# Windows (PowerShell):
irm https://raw.githubusercontent.com/karlmoriaty/office-command-operate/main/install.ps1 | iex
cmd_op.install() does the same from Python. If the CLI can't be found or
installed, the SDK raises a clear error pointing here (never a cryptic
FileNotFoundError).
Install
pip install cmd-op-sdk # once published — note: import name is `cmd_op`
# or, from a checkout of this repo:
pip install ./sdk/python
The pip/distribution name is cmd-op-sdk, but you import cmd_op
(distribution name ≠ import name, like pip install pillow → import PIL).
Zero third-party dependencies (standard library only).
Quickstart
import cmd_op
# create() makes a new file and returns a live session handle;
# open() does the same for an existing file. Both return a Document.
with cmd_op.create("report.xlsx", "--force") as doc:
doc.send({"command": "set", "path": "/Sheet1/A1",
"props": {"text": "Region", "bold": "true"}})
doc.send({"command": "set", "path": "/Sheet1/B1", "props": {"formula": "=SUM(B2:B9)"}})
# read one back (returns the parsed JSON envelope)
node = doc.send({"command": "get", "path": "/Sheet1/A1"})
print(node["data"]["results"][0]["text"]) # -> Region
# many edits in ONE pipe round-trip
doc.batch([
{"command": "set", "path": "/Sheet1/A2", "props": {"text": "North"}},
{"command": "set", "path": "/Sheet1/A3", "props": {"text": "South"}},
])
doc.send({"command": "save"})
# leaving `with` closes the resident (which flushes to disk)
# borrow an already-running resident without owning it: skip `with`/close()
d = cmd_op.open("report.xlsx")
print(d.send({"command": "view", "mode": "stats"}, as_json=False))
See demo.py for a fuller example.
The command dict
send(item) and batch([item, ...]) take the cmd_op batch-item shape:
{ "command": "set", // or "op"; picks the cmd_op command
"path": "/Sheet1/A1", // every key except command/op/props is forwarded
"props": { "text": "hi" } } // verbatim as a command argument
Keys are cmd_op's own batch fields (command/op, path, parent, type,
index, after, before, to, selector, mode, depth, part, xpath,
action, xml) plus a nested props. The client maintains no field list of its
own — run cmd_op help (or see the batch docs) for the full reference.
send(..., as_json=False) requests plain-text output (e.g. view / raw /
dump), mirroring the CLI's --json toggle.
Errors & resilience
- Transport/process failures raise
cmd_op.CmdOpError(.codecarries the exit code). Business outcomes (e.g.validatefailing, a bad path) are not exceptions — they live in the returned envelope'ssuccessfield, same as the CLI's exit code. - If the resident has gone (crash, idle-timeout, missing pipe),
send/batchtransparently restart it and retry once. If it's alive but the pipe is unresponsive (busy), they raise rather than risk racing the live resident.
Use it as an MCP server
The cmd_op binary that this SDK provisions is also an MCP stdio server, so you can give Claude Code, Cursor, VS Code, LM Studio, or opencode direct document tools without a separate package:
cmd_op mcp claude # also: cursor, vscode, lmstudio, opencode
cmd_op mcp list
The generic configuration for any MCP client:
{
"mcpServers": {
"cmd_op": {
"command": "cmd_op",
"args": ["mcp"]
}
}
}
Versioning
This client derives the resident's pipe address from the document path the same way cmd_op does. That derivation is the one piece coupled to cmd_op internals, so keep the client version compatible with your installed cmd_op.
Metadata
Release files for cmd-op-sdk 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cmd_op_sdk-1.3.2.tar.gz | 18.1 kB | Without provenance | Details for cmd_op_sdk-1.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cmd_op_sdk-1.3.2-py3-none-any.whl | Python 3 | none | any | Details for cmd_op_sdk-1.3.2-py3-none-any.whl |
Total release size: 33.8 kB
Release files / cmd_op_sdk-1.3.2.tar.gz
| Download URL | cmd_op_sdk-1.3.2.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
adb3aad847f73869027c792fe32d0d292d63ee1f1be9c5f6a767c9e1aaa91924
|
|
BLAKE2b-256 checksum How to use checksums |
7d8239d000faf605f5c7929e39f65fedade790bdec68d3b999fc784d358a5a7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.5
|
Release files / cmd_op_sdk-1.3.2-py3-none-any.whl
| Download URL | cmd_op_sdk-1.3.2-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2923df35bbade4c15b15c31b0bd6c3b6cf1b947b5b9cca9e6010bfddb8dcd2bf
|
|
BLAKE2b-256 checksum How to use checksums |
1a272cf97e9d0cd3613f33b995627217bc39b81109a6e8892ad71296ff6ba8d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.5
|
Security for cmd-op-sdk 1.3.2
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.