Skip to main content

python-docx-oss

A Python SDK for advanced creation and manipulation of Microsoft Word .docx files.

PyPI Python versions Code style: Ruff License: MIT

Overview

python-docx-oss is an independently evolving DOCX SDK built on the proven API foundation of python-docx. It keeps the familiar docx programming model while extending it for advanced OOXML and Open Packaging Convention (OPC) workflows.

Use it when an application needs more than basic paragraphs and tables: custom document metadata, application-owned XML, vector images, floating pictures, East Asian fonts, or low-level package and relationship access.

Capability Matrix

Capability Status Primary API
Documents, paragraphs, tables, styles, sections, headers, and footers Stable Document() and document object APIs
Custom document properties Stable document.custom_properties
Custom XML lifecycle Stable add_custom_xml_part(), delete_custom_xml_part()
SVG and EMF images Stable add_picture()
Inline and floating pictures Stable add_picture(), add_float_picture()
Latin and East Asian font controls Stable run.font.name, run.font.hAnsi, run.font.eastAsia
Low-level OPC parts and relationships Stable document.part.package, part.rels
In-memory read, export, and independent copies Stable Document(), to_bytes(), copy()
Document sanitization Development document.sanitize()
Package inspection and diff Planned —

Installation

python -m pip install python-docx-oss

The distribution name is python-docx-oss, but the Python import namespace remains docx:

from docx import Document

[!WARNING] python-docx and python-docx-oss provide the same docx import namespace. Do not install both distributions in the same Python environment.

python-docx-oss currently supports Python 3.12, 3.13, and 3.14.

Quick Start

Create a document entirely in memory:

from io import BytesIO

from docx import Document

document = Document()
document.add_heading("Quarterly Report", level=1)
document.add_paragraph("Generated entirely in memory.")

output = BytesIO()
document.save(output)

docx_bytes = output.getvalue()

The same APIs also accept filesystem paths:

document = Document("input.docx")
document.add_paragraph("Appended by python-docx-oss.")
document.save("output.docx")

Advanced Capabilities

Custom properties

document = Document()
document.custom_properties["workflow_status"] = "approved"
document.custom_properties["revision"] = 3

Custom properties are visible in Microsoft Word and stored in /docProps/custom.xml. See Working with custom properties.

Custom XML

custom_xml = document.part.add_custom_xml_part(
    '<order xmlns="urn:example:orders" id="A-001"/>',
)
custom_xml.add_item("status", "ready")

See Working with Custom XML for lifecycle and compatibility considerations.

East Asian fonts

run = document.add_paragraph().add_run("English 与中文")
run.font.name = "Open Sans"
run.font.eastAsia = "Microsoft YaHei"

SVG and EMF streams can be passed to the standard picture APIs. Floating pictures are available through Document.add_float_picture() and Run.add_float_picture().

Compatibility and Scope

  • The project maintains broad compatibility with the public python-docx API while following its own versioning and product roadmap.
  • Compatibility does not extend to every private or internal python-docx API. Test those integrations before migrating production systems.
  • The SDK focuses exclusively on DOCX. It is not a general XLSX/PPTX Office suite.
  • It edits document structure but does not implement Word's page-layout rendering engine.
  • CLI, MCP, web, desktop, and Agent runtimes belong in separate packages that consume this SDK.

Documentation

Quality and Testing

The test suite combines unit and acceptance coverage with in-memory round-trip tests using documents created by Microsoft Word. The integration fixtures cover floating pictures, SVG fallback relationships, East Asian fonts, Custom XML parts, and core OPC package preservation.

For local development:

uv sync
uv run pytest
uv run ruff check .
uv run pyright

Project Status

The current focus is stabilizing the independent SDK baseline, its in-memory workflows, and its advanced OOXML capabilities before expanding document inspection, comparison, sanitization, composition, and validation APIs.

Credits

This project builds on the original work of python-docx creator Steve Canny and its contributors. python-docx-oss is maintained by Ethan St Lee and its contributors.

Why “OSS”?

In Brazilian jiu-jitsu, “oss” is a greeting and an expression of respect. It reflects the same spirit of discipline and collaboration behind this project.

License

python-docx-oss is released under the MIT License.

Support

If this project is useful to you, you can support its continued development through the donation page.

Metadata

Release files for python-docx-oss 0.3.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 python-docx-oss 0.3.0
File Size Uploaded
python_docx_oss-0.3.0.tar.gz 8.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-docx-oss 0.3.0
File Interpreter ABI Platform
python_docx_oss-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 MB

Release files / python_docx_oss-0.3.0.tar.gz

Download URL python_docx_oss-0.3.0.tar.gz
Size 8.8 MB
Tags Source
SHA-256 checksum
How to use checksums
edbd89798753dc8943e57cb9a0171f8c332a1d8261a68269deaf50c70e638fc2
BLAKE2b-256 checksum
How to use checksums
4540f73aa4d53ec1bf1c43697b9a831df12b6178dea83e06f005b12a6cdbe9e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.7

Release files / python_docx_oss-0.3.0-py3-none-any.whl

Download URL python_docx_oss-0.3.0-py3-none-any.whl
Size 271.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b45d9f0d7f1e82dbe0211a38503c53662ddddc01132516e07087989207b1ad4d
BLAKE2b-256 checksum
How to use checksums
9b7c7f9a7bb13cac8c0dcb3d352212c8334a74d2eba36b4089e11806a81f87a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.7
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