Skip to main content

athena-python-docx

Drop-in replacement for python-docx that connects to Athena's Keryx-backed Word document stack.

Install it in an environment of its own

athena-python-docx installs as the docx module and replaces stock python-docx in the Python it is installed into. Every script there then imports this SDK, at whatever release went in, and a stale copy goes unnoticed. Never install it into a system or shared Python. Run with uv, which makes a throwaway environment per run, or keep a virtual environment for it:

# The current Athena SDK, for an Athena Word document (asset_...):
uv run --with athena-python-docx python edit_document.py

# Stock python-docx:
uv run --with python-docx python build_local_docx.py

# Or a virtual environment of its own:
python -m venv .venv-athena && .venv-athena/bin/pip install -U athena-python-docx
.venv-athena/bin/python edit_document.py

Inside a directory with a pyproject.toml of its own, uv run installs that project too; add --no-project to leave it out. python -m pip show athena-python-docx python-docx names what an environment has installed, and the release of each. Athena's executors, computers and session VMs come with a current SDK installed: use that one and don't pip install over it. When the DOCX Studio a script talks to ships a release far newer than the one installed (a newer major release, or ten or more minor releases on), the SDK says so once per process with a StaleSdkWarning that names both releases and the command that updates; ATHENA_SDK_SKIP_VERSION_CHECK=1 silences it.

Quick start

from docx import Document
from docx.shared import Inches, Pt, RGBColor

# Open an existing Word document asset by its Athena asset_id
with Document("asset_abc123") as doc:
    doc.add_heading("Market Analysis", level=1)

    p = doc.add_paragraph()
    r = p.add_run("Revenue grew ")
    highlight = p.add_run("12.3% year-over-year")
    highlight.bold = True
    highlight.font.color.rgb = RGBColor(0x00, 0x80, 0x00)
    p.add_run(".")

    t = doc.add_table(rows=2, cols=2, style="TableGrid")
    t.cell(0, 0).text = "Segment"
    t.cell(0, 1).text = "Revenue"
    t.cell(1, 0).text = "Enterprise"
    t.cell(1, 1).text = "$4.3M"

    doc.save()

Local files

Document(), Document(path) and Document(stream) open a .docx file on this machine with python-docx 1.2.0's own code, vendored in the package, as python-docx does: no network, no Athena credentials, and document.save(path_or_stream) writes python-docx's file. python-docx's own dependencies, lxml and typing_extensions, install with the SDK.

from docx import Document

document = Document("report.docx")           # a local file, python-docx's document
document.add_paragraph("Reviewed.")
document.save("report-reviewed.docx")

athena_doc = Document("asset_abc123")        # an Athena Word document, live
new_doc = Document.create(name="Q4 Report")  # a new one

API parity rule

This SDK mirrors python-docx's public API exactly. See CLAUDE.md for the full contract.

import docx is python-docx 1.2.0's package: docx.__version__ is "1.2.0" and from docx import * binds Document alone. What athena-python-docx adds is in one namespace, docx.athena: the SDK release (docx.athena.__version__, also docx.__athena_sdk_version__), docx.athena.flush_all() and discard_all(), and the warning classes an Athena document emits. docx.flush_all(), from docx import Pt and the warnings at python-docx's module paths still work for one release, each with a DeprecationWarning.

Packages that depend on python-docx

This SDK installs python-docx's docx package under its own distribution name, so do not install python-docx beside it: pip install docxtpl (or anything else that depends on python-docx) would fetch stock python-docx, whose files overwrite the SDK's. Install the SDK's stand-in for python-docx first, a metadata-only python-docx 1.2.0+athena.<release> that such an install resolves against. Its builder, scripts/build_python_docx_provides.py, needs only the standard library; it is in this directory and in the SDK's source distribution on PyPI (pip download --no-deps --no-binary :all: athena-python-docx). Run it with the interpreter the SDK is installed in:

python scripts/build_python_docx_provides.py --out provides
pip install --no-deps provides/python_docx-*.whl
python scripts/build_python_docx_provides.py --verify
pip install docxtpl

Athena's executor images install it already.

Development

uv venv
uv pip install -e ".[dev]"
uv run pytest tests/ -x

DocX Execution Lab

For fast local repros against real Athena document assets, use the headless runner in scripts/docx_exec_lab.py. It executes an arbitrary Python snippet with this checkout of athena-python-docx, captures stdout/stderr/errors/timings, and can export the resulting .docx for text assertions. scripts/docx_exec_lab_server.py adds a local UI with an Olympus Word document embed preview pane. See DOCX_EXEC_LAB.md.

Environment variables

Required when connecting to DOCX Studio (set by the Athena backend in the execute_word_document_code executor sandbox):

  • ATHENA_DOCX_BASE_URL — DOCX Studio API base URL
  • ATHENA_DOCX_API_KEY — Athena API key or service-issued DOCX Studio token

Without ATHENA_DOCX_API_KEY (and without api_key=), the SDK uses ATHENA_API_KEY. When ATHENA_API_URL is set too (the bare Athena URL or one ending in /api/v0), an opened document's calls carry a 15-minute token Athena mints for that document alone (POST /api/v0/assets/{asset_id}/studio-token), read-only for reads; Document.create() and its upload still send the key (docx/_asset_token.py).

With no ATHENA_DOCX_API_KEY (and no api_key=), Document.create() asks Athena's public API to make the document (POST /api/v0/assets/create, docx/_public_create.py). That create, like the one sent to DOCX Studio, carries an Idempotency-Key (idempotency_key=, else a new one): sent again with the same key, by the same user in the same workspace, it is answered with the document the first one made instead of a second. A create that gets no answer raises docx.errors.CreateTimeoutError naming the key, after sending it again where Athena says every server takes keys; pass that key back as Document.create(idempotency_key=...) to find the document.

License

MIT

Metadata

Release files for athena-python-docx 0.64.0

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

Source distribution (sdist)

Source distribution for athena-python-docx 0.64.0
File Size Uploaded Provenance Actions
athena_python_docx-0.64.0.tar.gz 2.0 MB Without provenance Details for athena_python_docx-0.64.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for athena-python-docx 0.64.0
File Interpreter ABI Platform Actions
athena_python_docx-0.64.0-py3-none-any.whl Python 3 none any Details for athena_python_docx-0.64.0-py3-none-any.whl

Total release size: 2.8 MB

Release files / athena_python_docx-0.64.0.tar.gz

Download URL athena_python_docx-0.64.0.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
d0516862087a7d22c6cb10c103dfc8c30bb12b0de0378789b57ac21138de1e17
BLAKE2b-256 checksum
How to use checksums
c1c2b6ef0ed8a4b7d8b395400fa075088770096a5144f2886e7a540103ae8ff2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / athena_python_docx-0.64.0-py3-none-any.whl

Download URL athena_python_docx-0.64.0-py3-none-any.whl
Size 820.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64f4ad0043ed5b6674e39d02982cb18dc6bbe152737536b9d8444e0ec47ea893
BLAKE2b-256 checksum
How to use checksums
321e0902e4ac99b19d4d2bb2b3aa451e2bc9c6aa4d77cfc89138def1d1d27392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for athena-python-docx 0.64.0

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.

Release history Release notifications | RSS feed

This release

0.64.0 This release

2 release files No provenance

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