Skip to main content

undoc

High-performance Microsoft Office document extraction to Markdown.

Installation

pip install undoc

Usage

Basic Usage

from undoc import parse_file

# Parse a document
doc = parse_file("document.docx")

# Convert to Markdown
markdown = doc.to_markdown()
print(markdown)

# Convert to plain text
text = doc.to_text()

# Convert to JSON
json_data = doc.to_json()

With Context Manager

from undoc import parse_file

with parse_file("document.xlsx") as doc:
    print(doc.to_markdown(frontmatter=True))
    print(f"Sections: {doc.section_count}")
    print(f"Resources: {doc.resource_count}")

Parse from Bytes

from undoc import parse_bytes

with open("document.pptx", "rb") as f:
    data = f.read()

doc = parse_bytes(data)
markdown = doc.to_markdown()

Extract Resources (Images)

from undoc import parse_file

doc = parse_file("document.docx")

# Get all resource IDs
resource_ids = doc.get_resource_ids()

for rid in resource_ids:
    # Get resource metadata
    info = doc.get_resource_info(rid)
    print(f"Resource: {info['filename']} ({info['mime_type']})")

    # Get resource binary data
    data = doc.get_resource_data(rid)

    # Save to file
    with open(info['filename'], 'wb') as f:
        f.write(data)

Document Metadata

from undoc import parse_file

doc = parse_file("document.docx")

print(f"Title: {doc.title}")
print(f"Author: {doc.author}")
print(f"Sections: {doc.section_count}")
print(f"Resources: {doc.resource_count}")

Handling Failures

UndocError.kind says why a call failed, so you can react to the reason instead of matching on message text:

from undoc import ErrorKind, UndocError, parse_file

try:
    doc = parse_file(path)
    print(doc.to_markdown())
except UndocError as err:
    if err.kind is ErrorKind.ZIP_ARCHIVE:
        print("The file is damaged.")
    elif err.kind in (ErrorKind.UNKNOWN_FORMAT, ErrorKind.UNSUPPORTED_FORMAT):
        print("Not a supported Office document.")
    elif err.kind is ErrorKind.ENCRYPTED:
        print("The document is encrypted.")
    else:
        # Also the right branch for a reason this build has no name for.
        print(f"Extraction failed ({err.kind}): {err}")

The numbers behind ErrorKind are a stable ABI contract: a new reason takes the next free number and existing ones are never renumbered. Always keep a final else — an unrecognised value arrives as a plain int rather than an ErrorKind, so that a newer native library stays usable. kind is ErrorKind.OTHER for failures raised by the wrapper itself, and never ErrorKind.NONE (which means success).

Supported Formats

  • DOCX - Microsoft Word documents
  • XLSX - Microsoft Excel spreadsheets
  • PPTX - Microsoft PowerPoint presentations

Features

  • RAG-Ready Output: Structured Markdown optimized for RAG/LLM applications
  • High Performance: Native Rust implementation via FFI
  • Asset Extraction: Images and embedded resources
  • Metadata Preservation: Document properties, styles, formatting
  • Cross-Platform: Windows, Linux, macOS (Intel & ARM)

API Reference

Functions

  • parse_file(path) - Parse document from file path
  • parse_bytes(data) - Parse document from bytes
  • version() - Get library version

Undoc Class

Conversion Methods

  • to_markdown(frontmatter=False, escape_special=False, paragraph_spacing=False) - Convert to Markdown
  • to_text() - Convert to plain text
  • to_json(compact=False) - Convert to JSON
  • plain_text() - Get plain text (fast extraction)

Properties

  • title - Document title
  • author - Document author
  • section_count - Number of sections
  • resource_count - Number of resources

Resource Methods

  • get_resource_ids() - List of resource IDs
  • get_resource_info(id) - Resource metadata
  • get_resource_data(id) - Resource binary data

License

MIT License - see LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

undoc-0.10.0.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

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

undoc-0.10.0-py3-none-any.whl (4.3 MB view details)

Uploaded Python 3

File details

Details for the file undoc-0.10.0.tar.gz.

File metadata

  • Download URL: undoc-0.10.0.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for undoc-0.10.0.tar.gz
Algorithm Hash digest
SHA256 93bb79be045098dd37cc7195c27680b5f5d664c541f65265df0535550b4c5900
MD5 f1e347c66672b29949c1679bc908bce9
BLAKE2b-256 324ebcb688b7552a0ef1443c2fa027719b8acd85829be37d994afb5777ebbd08

See more details on using hashes here.

File details

Details for the file undoc-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: undoc-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for undoc-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1baa77c0fd038c0f3b1efc61cc9a54a792e135b14ff95ce15ae31e04540685b0
MD5 6266d7b096984d6fd214d864ffbfa3d2
BLAKE2b-256 018632cb7f256fd2ddc3e8709ce21f79e5d55a6b596b1b7b77745c393fe0e33f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 files

0.9.0

2 files

0.8.1

1 file

0.8.0

1 file

0.7.0

1 file

0.6.0

1 file

0.5.5

1 file

0.5.4

1 file

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5.0

1 file

0.3.1

1 file

0.3.0

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.20

1 file

0.1.19

1 file

0.1.18

1 file

0.1.17

1 file

0.1.16

1 file

0.1.15

1 file

0.1.13

1 file

0.1.11

1 file

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