Skip to content
CenterForOpenSciencePublic

About

An extendable docx file format parser and converter

Resources

Stars

193 stars

Watchers

13 watching

Forks

Repository files navigation

PyDocX

CI

PyDocX is an extensible Python library for reading Microsoft Word DOCX (Office Open XML) documents and exporting their content to markup.

It includes an HTML exporter and a command-line interface. Developers can customize the HTML output or implement exporters for other markup formats using the underlying document model and export framework.

Features

  • Built-in DOCX-to-HTML conversion.
  • Support for headings, paragraphs, text formatting, hyperlinks, and images.
  • Support for nested lists and tables, including merged cells.
  • Customizable export behavior through exporter subclasses.
  • Input from file paths, binary file objects, or file-like objects.

HTML is the built-in output format. Other formats require a custom exporter. PyDocX does not aim to reproduce Word's page layout exactly.

Installation

pip install pydocx

Quick start

Convert a document from the command line:

pydocx --html input.docx output.html

Or use the Python API:

from pydocx import PyDocX

html = PyDocX.to_html("input.docx")

You can also pass an open binary file:

from pydocx import PyDocX

with open("input.docx", "rb") as document:
    html = PyDocX.to_html(document)

Custom exporters

Use PyDocXHTMLExporter directly when you need control over HTML conversion:

from pydocx.export import PyDocXHTMLExporter

exporter = PyDocXHTMLExporter("input.docx")
html = exporter.export()

Subclass PyDocXHTMLExporter to customize HTML output, or pydocx.export.base.PyDocXExporter to implement another markup format.

See the extension guide for details.

Documentation and support

Contributing

Bug reports, documentation improvements, and code contributions are welcome. When reporting a conversion problem, include your Python and PyDocX versions, the expected output, and a minimal DOCX example with sensitive information removed.

License

PyDocX is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

About

An extendable docx file format parser and converter

Resources

Stars

193 stars

Watchers

13 watching

Forks

Releases

Packages

Used by

Contributors

Languages