Skip to main content

Excel automation tool for agents in headless environments

Project description

headless-excel

A light wrapper around openpyxl providing ergonomic APIs for agents. Uses LibreOffice in headless mode to evaluate formulas. Can be used in CLI or SDK mode.

Requirements

  • Python 3.10+
  • LibreOffice (libreoffice-calc)

Installation

pip install headless-excel

For the live viewer (watch command):

pip install headless-excel[watch]

Install LibreOffice:

# macOS
brew install --cask libreoffice

# Ubuntu/Debian
sudo apt install libreoffice libreoffice-calc

# Windows
winget install -e --id TheDocumentFoundation.LibreOffice

Verify setup:

headless-excel check

SDK

Use as a Python library. All workbook and worksheet objects are proxies over openpyxl. If a proxy method doesn't exist, it forwards to the underlying openpyxl object.

from headless_excel import create, run

# Create new workbook
with create("model.xlsx") as ctx:
    ws = ctx.active
    ws["A1"] = 100
    ws["A2"] = 200
    ws["A3"] = "=A1+A2"

    ctx.sync()  # saves, recalculates, reloads
    print(ws["A3"].value)  # 300

# Open existing workbook
with run("model.xlsx") as ctx:
    ws = ctx.active
    ws["A1"] = 500

    ctx.sync()
    print(ws["A3"].value)  # 700

CLI

headless-excel check                    # verify setup
headless-excel create FILE              # create empty workbook
headless-excel eval FILE CODE           # execute Python code
headless-excel eval FILE -              # read code from stdin
headless-excel watch FILE [--open]      # live viewer (requires [watch] extras)
headless-excel libreoffice start        # start daemon
headless-excel libreoffice stop         # stop daemon
headless-excel libreoffice status       # check daemon status

The eval command injects the following into globals:

Name Description
ctx ExcelContext for the file (same as returned by run() and create())
NumberFormats Class with predefined number format constants (e.g., NumberFormats.CURRENCY, NumberFormats.PERCENT)

Example

headless-excel create model.xlsx
headless-excel eval model.xlsx "
ws = ctx.active
ws.write('A1', [
    ['Product', 'Q1', 'Q2', 'Total'],
    ['Widget', 100, 150, '=B2+C2'],
])
ctx.sync()
print(ws.range('A1:D2').dump())
"

Daemon

Formula recalculation requires libreoffice-calc. By default, each sync() spawns a new LibreOffice process.

The daemon is a TCP server running inside a persistent LibreOffice instance. It accepts commands to recalculate workbooks via the UNO API, avoiding startup overhead:

headless-excel libreoffice start

The daemon auto-exits after 5 minutes of inactivity. sync() automatically tries to start the daemon, falling back to a cold headless LibreOffice run only if that fails.

You can manually control the daemon lifecycle via CLI:

headless-excel libreoffice start   # start daemon
headless-excel libreoffice stop    # stop daemon
headless-excel libreoffice status  # check if running

Or via SDK:

from headless_excel import start_daemon, stop_daemon, is_daemon_running

start_daemon()
stop_daemon()
print(is_daemon_running())

Configuration

Variable Default Description
HEADLESS_EXCEL_PORT 49152 Preferred TCP port (auto-finds free port if unavailable)
HEADLESS_EXCEL_IDLE_TIMEOUT 300 Seconds of inactivity before daemon auto-exits
HEADLESS_EXCEL_MAX_ERRORS 10 Max formula errors to display when syncing

Documentation

  • API Reference — Full SDK documentation
  • Hooks — Custom hooks for formatting, validation, and linting
  • Roadmap — Planned features and improvements

License

Apache 2.0

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

headless_excel-0.1.0.tar.gz (157.6 kB view details)

Uploaded Source

Built Distribution

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

headless_excel-0.1.0-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

Details for the file headless_excel-0.1.0.tar.gz.

File metadata

  • Download URL: headless_excel-0.1.0.tar.gz
  • Upload date:
  • Size: 157.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for headless_excel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70de6599e7acbdc54e90c1e985388a46d5f4e39d65448701da30fec911ab79f7
MD5 9368d5260083555f8df0b0e7bb1af4a4
BLAKE2b-256 cff83f508d1c9726fb83205ff4fcba49a30dc3a204e4a16ecc304d53dc76036d

See more details on using hashes here.

Provenance

The following attestation bundles were made for headless_excel-0.1.0.tar.gz:

Publisher: publish.yml on hewliyang/headless-excel

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

File details

Details for the file headless_excel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: headless_excel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 51.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for headless_excel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47604d109987ac5e0ed17c4183e21c2f5176243916f90f9b7b7fd5ef87d66917
MD5 03b1c032f2a3cbb14a55db5c094520f0
BLAKE2b-256 4480c25f43c38f80b7c6de31175ac431a80b5023620ac49c106a3ac1a85b90e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for headless_excel-0.1.0-py3-none-any.whl:

Publisher: publish.yml on hewliyang/headless-excel

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