Pure-Python text extraction for classic Microsoft Word .doc files.
Project description
legacy-doc
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
.docfiles - 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 textparser: parser nameversion: parser versionmetadata: lightweight extraction metadatawarnings: 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file legacy_doc-0.2.1.tar.gz.
File metadata
- Download URL: legacy_doc-0.2.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3573a034638af1ebbbe1a727baf18b2f69e6ad6439e4650be59aadc069a9bb42
|
|
| MD5 |
50430d571f76675781d4178f1ac3ae30
|
|
| BLAKE2b-256 |
99ec7cc1afd576a1508aafdd3d6e7cb126b993940772703d35243741fa49b220
|
Provenance
The following attestation bundles were made for legacy_doc-0.2.1.tar.gz:
Publisher:
publish.yml on lcorrigan704/legacy-doc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
legacy_doc-0.2.1.tar.gz -
Subject digest:
3573a034638af1ebbbe1a727baf18b2f69e6ad6439e4650be59aadc069a9bb42 - Sigstore transparency entry: 1656134617
- Sigstore integration time:
-
Permalink:
lcorrigan704/legacy-doc@33aac7cace0dc30d95e671df5aaa825e4c2223a1 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/lcorrigan704
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@33aac7cace0dc30d95e671df5aaa825e4c2223a1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file legacy_doc-0.2.1-py3-none-any.whl.
File metadata
- Download URL: legacy_doc-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51c428238efc48ef77b32fb7e9e0f35081eeb0a88e181dd3f793189dc63355e6
|
|
| MD5 |
267507e1eccfe2d39e078a8fa877bcbe
|
|
| BLAKE2b-256 |
b2c0c20afbf15f0f453be9202ce2b9e4b4f4456f1661a8413d437237ef428ef0
|
Provenance
The following attestation bundles were made for legacy_doc-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on lcorrigan704/legacy-doc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
legacy_doc-0.2.1-py3-none-any.whl -
Subject digest:
51c428238efc48ef77b32fb7e9e0f35081eeb0a88e181dd3f793189dc63355e6 - Sigstore transparency entry: 1656136168
- Sigstore integration time:
-
Permalink:
lcorrigan704/legacy-doc@33aac7cace0dc30d95e671df5aaa825e4c2223a1 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/lcorrigan704
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@33aac7cace0dc30d95e671df5aaa825e4c2223a1 -
Trigger Event:
release
-
Statement type: