Skip to main content

legacy-doc

Downloads

legacy-doc is a small, dependency-free Python library for extracting readable text from classic Microsoft Word .doc files.

It is intentionally narrow:

  • supports OLE Compound File Word 97-2003 .doc files
  • extracts normalized text from the Word piece table
  • rejects encrypted, malformed, non-OLE, or unsafe files clearly
  • does not execute macros, embedded objects, links, scripts, or external references
  • does not use native binaries, LibreOffice, antiword, or third-party parsers

Install

pip install legacy-doc

Usage

from legacy_doc import extract_text

with open("document.doc", "rb") as file:
    result = extract_text(file.read())

print(result.text)
print(result.metadata)

metadata always includes extracted text size fields and lightweight OLE inventory fields. When present in the document's saved Word metadata, it can also include values such as title, author, company, page count, word count, character count, creation time, and last-saved time.

API

extract_text(document_bytes: bytes, *, options: ExtractionOptions | None = None) -> DocExtractionResult

DocExtractionResult contains:

  • text: normalized extracted text
  • parser: parser name
  • version: parser version
  • metadata: lightweight extraction metadata
  • warnings: non-fatal parser warnings

Example metadata:

{
    "chars": 1200,
    "bytes": 1225,
    "title": "Quarterly Notes",
    "author": "Liam Corrigan",
    "page_count": 4,
    "word_count": 210,
    "has_macros": False,
    "has_embedded_objects": False,
}

Limitations

This is not a full Microsoft Word renderer. It aims to recover readable text safely from common legacy .doc files. Formatting fidelity, OCR, images, macros, tracked changes, and embedded object extraction are out of scope.

page_count is read from saved Word document metadata when available. It is not recalculated by rendering the document, so it can be stale if the file was saved without updating document statistics.

Development

python -m pip install -e ".[dev]"
python -m pytest
python -m build
python -m twine check dist/*

The test suite includes small generated OLE WordDocument fixtures and malformed corpus cases for parser limits, encryption markers, missing piece tables, and cyclic FAT chains.

Security

legacy-doc treats input files as untrusted binary data. It performs bounded parsing, rejects encrypted documents, and never executes macros or embedded content. Report security issues privately before opening a public issue.

Metadata

Release files for legacy-doc 0.2.1

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

Source distribution (sdist)

Source distribution for legacy-doc 0.2.1
File Size Uploaded
legacy_doc-0.2.1.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for legacy-doc 0.2.1
File Interpreter ABI Platform
legacy_doc-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / legacy_doc-0.2.1.tar.gz

Download URL legacy_doc-0.2.1.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3573a034638af1ebbbe1a727baf18b2f69e6ad6439e4650be59aadc069a9bb42
BLAKE2b-256 checksum
How to use checksums
99ec7cc1afd576a1508aafdd3d6e7cb126b993940772703d35243741fa49b220
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

Release files / legacy_doc-0.2.1-py3-none-any.whl

Download URL legacy_doc-0.2.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51c428238efc48ef77b32fb7e9e0f35081eeb0a88e181dd3f793189dc63355e6
BLAKE2b-256 checksum
How to use checksums
b2c0c20afbf15f0f453be9202ce2b9e4b4f4456f1661a8413d437237ef428ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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