Skip to main content

officectrl — Python SDK

A thin Python SDK for the officectrl resident pipe. It does one thing: forward an officectrl 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 an officectrl 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 officectrl features work the day they ship without an SDK update.

The officectrl CLI (auto-installed if missing)

pip install officectrl-sdk installs only this SDK (the Python library); the real work is done by the officectrl binary. You don't have to install it yourself — if officectrl isn't found on your PATH (or in the default install location), the SDK provisions it on first use: it runs officectrl'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 officectrl install      # runs officectrl's official installer
# …or directly:
curl -fsSL https://raw.githubusercontent.com/karlmoriaty/OfficeCTRL/main/install.sh | bash
# Windows (PowerShell):
irm https://raw.githubusercontent.com/karlmoriaty/OfficeCTRL/main/install.ps1 | iex

officectrl.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 officectrl-sdk            # once published — note: import name is `officectrl`
# or, from a checkout of this repo:
pip install ./sdk/python

The pip/distribution name is officectrl-sdk, but you import officectrl (distribution name ≠ import name, like pip install pillow → import PIL).

Zero third-party dependencies (standard library only).

Quickstart

import officectrl

# create() makes a new file and returns a live session handle;
# open() does the same for an existing file. Both return a Document.
with officectrl.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 = officectrl.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 officectrl batch-item shape:

{ "command": "set",            // or "op"; picks the officectrl command
  "path": "/Sheet1/A1",        // every key except command/op/props is forwarded
  "props": { "text": "hi" } }  // verbatim as a command argument

Keys are officectrl'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 officectrl 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 officectrl.OfficeCtrlError (.code carries the exit code). Business outcomes (e.g. validate failing, a bad path) are not exceptions — they live in the returned envelope's success field, same as the CLI's exit code.
  • If the resident has gone (crash, idle-timeout, missing pipe), send/batch transparently restart it and retry once. If it's alive but the pipe is unresponsive (busy), they raise rather than risk racing the live resident.

Versioning

This client derives the resident's pipe address from the document path the same way officectrl does. That derivation is the one piece coupled to officectrl internals, so keep the client version compatible with your installed officectrl.

Metadata

Release files for officectrl-sdk 1.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for officectrl-sdk 1.2.5
File Size Uploaded Provenance Actions
officectrl_sdk-1.2.5.tar.gz 17.3 kB With provenance Details for officectrl_sdk-1.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for officectrl-sdk 1.2.5
File Interpreter ABI Platform Actions
officectrl_sdk-1.2.5-py3-none-any.whl Python 3 none any Details for officectrl_sdk-1.2.5-py3-none-any.whl

Total release size: 32.7 kB

Release files / officectrl_sdk-1.2.5.tar.gz

Download URL officectrl_sdk-1.2.5.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e617e940e2b76c16dcba60a5dc6a46153b2d478571cb2b4672905dc063612040
BLAKE2b-256 checksum
How to use checksums
166814ee129286d7c0bd32ecfaee0c12f85290e0363266d15f6e0234c897be31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / officectrl_sdk-1.2.5-py3-none-any.whl

Download URL officectrl_sdk-1.2.5-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42769bfe7382407fa5965c12cfb4579b493f1c95461fb91afd9b038095fab511
BLAKE2b-256 checksum
How to use checksums
bd06f523250fc94479e10694d91395a79e4ba26da68e348537495ce6f5545eab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for officectrl-sdk 1.2.5

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for officectrl_sdk-1.2.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page