Skip to main content

doc-files

Read what PDF, Office, OpenDocument and EPUB files say: their text and its structure, from headings and lists to tables and the pages, slides, sheets or chapters they sit in. You get a document model, plain text or Markdown.

Status: early development. The model and the command line may still change between releases.

What it reads

Files Needs
Word .docx, Excel .xlsx, PowerPoint .pptx nothing beyond Python
OpenDocument .odt .ods .odp nothing beyond Python
EPUB .epub nothing beyond Python
PDF .pdf pypdf (pip install "doc-files[pdf]")

The old binary Office formats (.doc, .xls, .ppt) are not read.

How it works

pip install "doc-files[pdf]"

doc-files dump report.docx                # plain text
doc-files dump deck.pptx -f markdown      # Markdown: a section per slide, notes included
doc-files dump budget.xlsx -f json        # the document model
doc-files formats                         # what can be read
import doc_files

doc = doc_files.read("deck.pptx")
for section in doc.sections:            # one per slide
    print(section.number, section.title, len(section.notes))
print(doc_files.to_markdown(doc))

What you get, and what you don't

The model keeps what a document means:

  • headings and their levels;
  • lists and their nesting;
  • tables with their merged cells;
  • emphasis and links;
  • a slide's speaker notes, page headers and footers, each in its own layer.

It leaves out how the document looks: positions, fonts, sizes, page layout. That is the point. The result can be searched, selected, copied and wrapped to any width, which a picture of a page cannot. To see what a file looks like, open it in the application that made it.

A PDF stores glyphs at positions rather than paragraphs and tables, so from a PDF you get the text of each page in reading order, and nothing guessed from the layout. A scanned PDF has no text at all; doc-files says so instead of returning an empty document. It does no OCR.

The model is specified in doc/MODEL_FORMAT.md. XeFM, a dual-pane file manager, uses it to show documents as text.

Safety

Documents are untrusted input. Zip members are read with a size cap (no zip bombs), and XML with a DOCTYPE is refused (no entity expansion). doc-files only reads files. It never writes or changes them.

License

MIT

Metadata

Release files for doc-files 0.1.0

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

Source distribution (sdist)

Source distribution for doc-files 0.1.0
File Size Uploaded
doc_files-0.1.0.tar.gz 31.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for doc-files 0.1.0
File Interpreter ABI Platform
doc_files-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 65.4 kB

Release files / doc_files-0.1.0.tar.gz

Download URL doc_files-0.1.0.tar.gz
Size 31.8 kB
Tags Source
SHA-256 checksum
How to use checksums
904ea00816f5fdb551054bca6e9a23dbb053ffca9cad0da801853b2e9dc85bb1
BLAKE2b-256 checksum
How to use checksums
3e7d2b2afd231a768de55c32e8dc6c24309e03cce6b309ca9a1817b725b6c966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / doc_files-0.1.0-py3-none-any.whl

Download URL doc_files-0.1.0-py3-none-any.whl
Size 33.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
504d8d2610f87f990264083862c1d5df1d480d64e08f8cb674554a8064628dcf
BLAKE2b-256 checksum
How to use checksums
a9ff0ec705702771ee66e10d59ddc95375303275685bf299c64b0fe0234bbd9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

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