Skip to main content

Pure-Python text extraction for classic Microsoft Word .doc files.

Project description

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.

Project details


Download files

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

Source Distribution

legacy_doc-0.2.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

legacy_doc-0.2.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file legacy_doc-0.2.0.tar.gz.

File metadata

  • Download URL: legacy_doc-0.2.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for legacy_doc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2b7113a86ead2457326f0f4e742378dd1373db3648e51260c683b9f602cd3924
MD5 6148a845905ed54148f963f4df8a08ca
BLAKE2b-256 a8ad4da408e58f460687ee786c7d1e0adb43df229aa0728584094ec28b86c869

See more details on using hashes here.

Provenance

The following attestation bundles were made for legacy_doc-0.2.0.tar.gz:

Publisher: publish.yml on lcorrigan704/legacy-doc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file legacy_doc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: legacy_doc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for legacy_doc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa90b1f4f253e9e8f0da50383fcee507e1aaba08367f7ec3655c80f7982567e
MD5 1f1a9bbf41c3072c92b6c51c60fc497b
BLAKE2b-256 c3c6aa95aaf91f8c622022d2efdf1763eed464ae281e888334bd9b56a4af0614

See more details on using hashes here.

Provenance

The following attestation bundles were made for legacy_doc-0.2.0-py3-none-any.whl:

Publisher: publish.yml on lcorrigan704/legacy-doc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page