# deanmalmgren/textract architecture

> Architecture diagram of the GitHub repository deanmalmgren/textract, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deanmalmgren/textract
- Repository: https://github.com/deanmalmgren/textract

## Overview

1. **Project type and scope**
   - This is a Python text-extraction library, with a small CLI wrapper on top.
   - Its core responsibility is: given an input file of many possible formats, return normalized text.

2. **Primary entry points**
   - `textract/cli.py` is the user-facing command-line interface.
   - `textract/bin/textract.py` is the executable entrypoint/wrapper that invokes the CLI.
   - The library package root `textract/__init__.py` likely exposes the public API for programmatic use.

3. **Dispatch and format selection**
   - The central architectural pattern is format-based dispatch.
   - `textract/parsers/` contains one parser module per file type, so the system routes input to a specialized handler based on extension or content type.
   - The parser set covers text, tabular, office documents, email, HTML, PDF/PS, images, audio, and spreadsheet formats.

4. **Parser layer as the main subsystem**
   - Parsers are the core of the repo: `txt`, `csv`, `tsv`, `psv`, `json`, `html`, `eml`, `msg`, `epub`, `doc`, `docx`, `odt`, `rtf`, `pptx`, `xls`, `xlsx`, `pdf`, `ps`, `tiff`, `png`, `jpg`, `gif`, `wav`, `mp3`, `ogg`.
   - Each parser is responsible for converting its source format into plain text and for handling format-specific edge cases.
   - `textract/parsers/utils.py` likely holds shared parser helpers and normalization logic.

5. **Specialized media handling**
   - The repo separates common media families into grouped modules such as `audio.py` and `image.py`, with thin format-specific modules like `mp3_parser.py`, `wav_parser.py`, `ogg_parser.py`, `png_parser.py`, `jpg_parser.py`, `gif_parser.py`, and `tiff_parser.py`.
   - This suggests a shared strategy for OCR or speech-to-text workflows, with per-extension adapters.

6. **External engine dependencies**
   - Some extraction paths depend on external backends rather than pure Python parsing.
   - The test fixtures indicate alternative engines for the same format, such as PDF extraction via `pdfminer`, `pdftotext`, or OCR via `tesseract`, and audio transcription via `google` or `sphinx`.
   - Architecturally, these are optional backend boundaries behind the parser interface.

7. **Error and presentation boundaries**
   - `textract/exceptions.py` defines repo-specific failure modes, which likely wrap unsupported format, missing dependency, or parse failure conditions.
   - `textract/colors.py` suggests terminal-friendly CLI output styling, separate from the extraction logic itself.

8. **Data flow**
   - Input file path enters through CLI or Python API.
   - The dispatcher selects a parser.
   - The parser may call a native library or an external command/service.
   - The result is normalized into plain text and returned to the caller or printed by the CLI.

9. **Testing architecture**
   - The `tests/` tree is organized by file type, with paired `raw_text.*` and `standardized_text.*` fixtures.
   - This shows the main contract: extracted output should match expected normalized text across many formats.
   - There are also tests for special filenames and failure cases, indicating robustness around path handling and unsupported inputs.

10. **Documentation and release/tooling**
   - `docs/` is a full Sphinx documentation site, including installation, CLI usage, Python API, and changelog.
   - GitHub Actions and `uv.lock`/`pyproject.toml` indicate CI and locked dependency management.
   - `scripts/bump_version.py` and the release notes in `README.rst` show a straightforward packaging/release workflow for a library distributed on PyPI.

11. **How to draw the architecture**
   - Draw a thin CLI/API front end feeding a central parser dispatcher.
   - From there, branch into many format-specific parser modules.
   - Show several parsers calling out to external engines or libraries for OCR, PDF, audio, or document conversion.
   - Keep tests and docs as supporting subsystems around the core extraction pipeline.

Main entry points: [`textract/parsers/__init__.py`](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/__init__.py) (Dispatcher), [`textract/cli.py`](https://github.com/deanmalmgren/textract/blob/master/textract/cli.py) (CLI), [`docs/index.rst`](https://github.com/deanmalmgren/textract/blob/master/docs/index.rst) (Docs), [`tests/base.py`](https://github.com/deanmalmgren/textract/blob/master/tests/base.py) (Test suite)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_entry["Entrypoints"]
  node_n_api["Public API<br/>package api<br/>[__init__.py]"]
  node_n_cli["CLI<br/>command interface<br/>[cli.py]"]
  node_n_bin["Wrapper<br/>executable shim<br/>[textract.py]"]
end

subgraph group_grp_core["Core extraction"]
  node_n_dispatch{{"Dispatcher<br/>format router<br/>[__init__.py]"}}
  node_n_utils["Parser utils<br/>shared helpers<br/>[utils.py]"]
  node_n_text["Text tables<br/>plain-text parsers<br/>[txt_parser.py]"]
  node_n_struct["Structured docs<br/>document parsers<br/>[docx_parser.py]"]
  node_n_pdf["PDF/PS<br/>page-layout parsers<br/>[pdf_parser.py]"]
  node_n_sheet["Spreadsheets<br/>spreadsheet parsers<br/>[xls_parser.py]"]
  node_n_audio["Audio<br/>[audio.py]"]
  node_n_image["Images<br/>image parsers<br/>[image.py]"]
  node_n_backends[("Backends<br/>external engines")]
end

subgraph group_grp_support["Support"]
  node_n_errors["Exceptions<br/>failure model<br/>[exceptions.py]"]
  node_n_colors["Colors<br/>cli styling<br/>[colors.py]"]
  node_n_tests["Test suite<br/>fixture-driven tests<br/>[base.py]"]
  node_n_docs["Docs<br/>[index.rst]"]
  node_n_release["Release tools<br/>packaging tooling<br/>[pyproject.toml]"]
end

node_n_bin -->|"invokes"| node_n_cli
node_n_cli -->|"dispatches"| node_n_dispatch
node_n_api -->|"calls"| node_n_dispatch
node_n_dispatch -->|"uses"| node_n_utils
node_n_dispatch -->|"routes to"| node_n_text
node_n_dispatch -->|"routes to"| node_n_struct
node_n_dispatch -->|"routes to"| node_n_pdf
node_n_dispatch -->|"routes to"| node_n_sheet
node_n_dispatch -->|"routes to"| node_n_audio
node_n_dispatch -->|"routes to"| node_n_image
node_n_text -.->|"direct"| node_n_backends
node_n_struct -.->|"depends on"| node_n_backends
node_n_pdf -.->|"depends on"| node_n_backends
node_n_sheet -.->|"depends on"| node_n_backends
node_n_audio -.->|"depends on"| node_n_backends
node_n_image -.->|"depends on"| node_n_backends
node_n_cli -->|"formats output"| node_n_colors
node_n_dispatch -->|"raises"| node_n_errors
node_n_cli -->|"handles"| node_n_errors
node_n_tests -.->|"verifies"| node_n_dispatch
node_n_tests -.->|"covers"| node_n_backends
node_n_docs -.->|"documents"| node_n_cli
node_n_docs -.->|"documents"| node_n_api
node_n_release -.->|"supports"| node_n_docs

click node_n_api "https://github.com/deanmalmgren/textract/blob/master/textract/__init__.py"
click node_n_cli "https://github.com/deanmalmgren/textract/blob/master/textract/cli.py"
click node_n_bin "https://github.com/deanmalmgren/textract/blob/master/textract/bin/textract.py"
click node_n_dispatch "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/__init__.py"
click node_n_utils "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/utils.py"
click node_n_text "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/txt_parser.py"
click node_n_struct "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/docx_parser.py"
click node_n_pdf "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/pdf_parser.py"
click node_n_sheet "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/xls_parser.py"
click node_n_audio "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/audio.py"
click node_n_image "https://github.com/deanmalmgren/textract/blob/master/textract/parsers/image.py"
click node_n_errors "https://github.com/deanmalmgren/textract/blob/master/textract/exceptions.py"
click node_n_colors "https://github.com/deanmalmgren/textract/blob/master/textract/colors.py"
click node_n_tests "https://github.com/deanmalmgren/textract/blob/master/tests/base.py"
click node_n_docs "https://github.com/deanmalmgren/textract/blob/master/docs/index.rst"
click node_n_release "https://github.com/deanmalmgren/textract/blob/master/pyproject.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_api,node_n_cli,node_n_bin toneBlue
class node_n_dispatch,node_n_utils,node_n_text,node_n_struct,node_n_pdf,node_n_sheet,node_n_audio,node_n_image,node_n_backends toneAmber
class node_n_errors,node_n_colors,node_n_tests,node_n_docs,node_n_release toneMint
```

## Components

### Entrypoints

User-facing interfaces that invoke text extraction.

- [Public API](https://github.com/deanmalmgren/textract/blob/master/textract/__init__.py): package api · Library root for programmatic use. · `textract/__init__.py`
- [CLI](https://github.com/deanmalmgren/textract/blob/master/textract/cli.py): command interface · Command-line entry point for users. · `textract/cli.py`
- [Wrapper](https://github.com/deanmalmgren/textract/blob/master/textract/bin/textract.py): executable shim · Executable launcher that invokes the CLI. · `textract/bin/textract.py`

### Core extraction

Dispatcher, parser families, and backend boundaries.

- [Dispatcher](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/__init__.py): format router · Selects a parser based on input format. · `textract/parsers/__init__.py`
- [Parser utils](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/utils.py): shared helpers · Common normalization and parser support code. · `textract/parsers/utils.py`
- [Text tables](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/txt_parser.py): plain-text parsers · Direct text and tabular text inputs. · `textract/parsers/txt_parser.py`
- [Structured docs](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/docx_parser.py): document parsers · Office, email, HTML, EPUB, JSON, and markup formats. · `textract/parsers/docx_parser.py`
- [PDF/PS](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/pdf_parser.py): page-layout parsers · Extraction for PDF and PostScript documents. · `textract/parsers/pdf_parser.py`
- [Spreadsheets](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/xls_parser.py): spreadsheet parsers · Spreadsheet-oriented extraction paths. · `textract/parsers/xls_parser.py`
- [Audio](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/audio.py): audio parsers · Speech-to-text extraction family. · `textract/parsers/audio.py`
- [Images](https://github.com/deanmalmgren/textract/blob/master/textract/parsers/image.py): image parsers · OCR-oriented image extraction family. · `textract/parsers/image.py`
- **Backends**: external engines · Optional native libraries, OCR tools, and transcription services.

### Support

Errors, presentation, tests, docs, and release tooling.

- [Exceptions](https://github.com/deanmalmgren/textract/blob/master/textract/exceptions.py): failure model · Repo-specific parse and dependency errors. · `textract/exceptions.py`
- [Colors](https://github.com/deanmalmgren/textract/blob/master/textract/colors.py): cli styling · Terminal presentation helpers for the CLI. · `textract/colors.py`
- [Test suite](https://github.com/deanmalmgren/textract/blob/master/tests/base.py): fixture-driven tests · Format-by-format contract tests for normalized text output. · `tests/base.py`
- [Docs](https://github.com/deanmalmgren/textract/blob/master/docs/index.rst): sphinx docs · Installation, CLI, API, and changelog documentation. · `docs/index.rst`
- [Release tools](https://github.com/deanmalmgren/textract/blob/master/pyproject.toml): packaging tooling · Version bumping, CI, and project metadata. · `pyproject.toml`

## Connections

- Wrapper → CLI: invokes · Executable wrapper starts the CLI.
- CLI → Dispatcher: dispatches · CLI routes user input into the extraction pipeline.
- Public API → Dispatcher: calls · Public API exposes programmatic extraction through the dispatcher.
- Dispatcher → Parser utils: uses · Dispatcher and parsers share common helpers.
- Dispatcher → Text tables: routes to · Plain-text and tabular inputs go to text-family parsers.
- Dispatcher → Structured docs: routes to · Document, markup, and email inputs go to structured parsers.
- Dispatcher → PDF/PS: routes to · Page-layout formats go to PDF/PostScript parsers.
- Dispatcher → Spreadsheets: routes to · Spreadsheet formats go to spreadsheet parsers.
- Dispatcher → Audio: routes to · Audio inputs go to speech-to-text parsers.
- Dispatcher → Images: routes to · Image inputs go to OCR parsers.
- Text tables → Backends: direct · Mostly direct parsing with minimal external dependencies.
- Structured docs → Backends: depends on · May rely on document libraries or format-specific engines.
- PDF/PS → Backends: depends on · Can use pdfminer, pdftotext, or OCR paths.
- Spreadsheets → Backends: depends on · Uses spreadsheet readers and conversion backends.
- Audio → Backends: depends on · Can call external transcription services or engines.
- Images → Backends: depends on · Uses OCR backends for image text extraction.
- CLI → Colors: formats output · CLI presentation uses terminal styling helpers.
- Dispatcher → Exceptions: raises · Unsupported formats and parse failures surface as repo errors.
- CLI → Exceptions: handles · CLI turns extraction errors into user-facing failure messages.
- Test suite → Dispatcher: verifies · Fixture suite exercises the extraction pipeline across formats.
- Test suite → Backends: covers · Tests encode alternative backend outputs for the same format.
- Docs → CLI: documents · Docs describe CLI usage and options.
- Docs → Public API: documents · Docs describe the Python API.
- Release tools → Docs: supports · Project tooling supports docs and distribution workflow.
