Registry / data / textract

textract

JSON →
library2.0.0pypypi✓ verified 87d ago

textract is a Python library designed to extract text from a wide variety of document formats, including PDFs, Word documents, images (via OCR), and audio files, providing a unified interface. The current stable version is 1.6.5, released in March 2022. While releases aren't on a strict schedule, the project is actively maintained with bug fixes and feature additions.

pip install textract
INSTALL
IMPORT
SIG · TEXTRACT
T
textract
datapythonv2.0.0
Install
7.9s avg
Import
16ms
Disk
139MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.016s · 138.6MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 7.9s · import 0.015s · 140MB
139MB installed
● package 139MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

process
✓ from textract import process
✗ import textract

Demonstrates how to extract text from a file using `textract.process()`. Note that for many file types (like PDF, DOCX, images), corresponding system-level dependencies are required for successful extraction. The output is a byte string, which typically needs to be decoded to UTF-8.

import textract import os # For demonstration, create a dummy text file dummy_file_path = 'example.txt' with open(dummy_file_path, 'w') as f: f.write('This is some sample text in a TXT file.') try: # Extract text from the dummy file text_bytes = textract.process(dummy_file_path) text_decoded = text_bytes.decode('utf-8') print(f"Extracted text: {text_decoded}") except Exception as e: print(f"An error occurred: {e}") finally: # Clean up the dummy file if os.path.exists(dummy_file_path): os.remove(dummy_file_path) # Example for a PDF (requires pdftotext system dependency) # try: # pdf_text = textract.process('path/to/document.pdf') # print(pdf_text.decode('utf-8')) # except Exception as e: # print(f"Could not process PDF: {e}. Is pdftotext installed and in PATH?")
textract --version
Debug
Known issues
breakingtextract relies heavily on external system-level libraries and executables (e.g., `pdftotext` for PDFs, `antiword` for .doc, `tesseract-ocr` for images, `sox` for audio). Without these, extraction for certain file types will fail with a `ShellError` or `FileNotFoundError`.
fix
Install the necessary system dependencies for the file types you intend to process. Refer to the official textract documentation for a comprehensive list based on your operating system (e.g., `apt-get` for Debian/Ubuntu, `brew` for macOS). For instance, for PDF files, ensure `poppler-utils` (which provides `pdftotext`) is installed.
affects: All versions
deprecatedAs of pip 24.1, `textract 1.6.5` has a non-standard dependency specifier (`extract-msg<=0.29.*`). This will result in a `DEPRECATION` warning during installation and may cause issues with future pip versions.
fix
While textract itself needs an update to fix this, users can often mitigate by pinning `pip` to an older version or, if possible, by manually installing `extract-msg` at the specified version before installing `textract`. Consider monitoring the project for an update addressing this, or using a fork like `textract-py3` if it resolves this issue.
affects: 1.6.5 (and potentially earlier versions with similar specifiers)
gotchaHandling special characters in filenames (e.g., spaces, non-ASCII characters) can sometimes lead to `FileNotFoundError` or `ShellError` when `textract` passes the filename to underlying command-line utilities.
fix
Ensure filenames are URL-encoded if being passed via web contexts, or consider sanitizing/simplifying filenames to alphanumeric characters and underscores before processing, especially on certain operating systems or with specific parsers.
affects: All versions
gotchaWhile textract 1.5.0 and newer officially support Python 3, older versions were primarily Python 2 compatible. Direct migration from very old codebases might expose subtle compatibility issues if not upgraded properly.
fix
Always use textract version 1.5.0 or higher for Python 3 projects. Ensure all project dependencies are also Python 3 compatible. Refer to release notes for `1.5.0` for detailed Python 3 migration notes.
affects: <1.5.0 for Python 3 incompatibility; potential minor issues in 1.5.0-1.6.5 for specific edge cases.
gotchaUnicodeDecodeError can occur, especially in non-standard environments or with files containing unusual encodings, as `textract` relies on `chardet` for input encoding inference and outputs byte strings that need proper decoding.
fix
Explicitly specify the desired output encoding in `textract.process(..., encoding='utf-8')`. If `chardet` struggles, pre-process the file to a known encoding or try different decoding strategies in your application.
affects: All versions
Upgrade
Version history
2.0.0latest on PyPI · released Apr 27, 2026
Audit
Dependencies
lxmlrequiredUsed for .docx parsing; requires system libraries like libxml2 and libxslt1.
pdfminer.sixrequiredUsed for .pdf parsing (default method); can benefit from system-level poppler-utils for better performance.
xlrdrequiredUsed for .xlsx parsing.
extract-msgrequiredUsed for .msg parsing; note on specific version constraint in warnings.
SpeechRecognitionoptionalUsed for audio file parsing.
Agent activity
28 hits · last 30 days
node
26
OpenAI (training)
1
Resources