Skip to main content

A Python library for extracting text from different types of files (PDF, DOCX, PPTX, XLSX, ODT, ecc.).

Project description

PyxTxt

PyPI version Python versions License: MIT

PyxTxt is a simple and powerful Python library to extract text from various file formats.
It supports PDF, DOCX, XLSX, PPTX, ODT, HTML, XML, TXT, legacy XLS files, and more.


✨ Features

  • Extracts text from both file paths and in-memory buffers (io.BytesIO).
  • Supports multiple formats: PDF, DOCX, PPTX, XLSX, ODT, HTML, XML, TXT, legacy Office files (.xls,.ppt).
  • Automatically detects MIME type using python-magic.
  • Compatible with modern and legacy formats.
  • Can handle streamed content without saving to disk (with some limitations).

📦 Installation

The library i modular so you can install all modules:

pip install pyxtxt[all]

or just the modules you need:

pip install pyxtxt[pdf,odf,docx,presentation,spreadsheet,html]

Beause needed libraries are common installing the html module will enable also SVG and XML. The architecture is designed to be able to grow with new modules to work with other formats as well.

⚠️ Note: You must have libmagic installed on your system (required by python-magic).

The pyproject.toml file should select the correct version for your system. But if you have any problem you can install it manually.

On Ubuntu/Debian:

sudo apt install libmagic1

On Mac (Homebrew):

brew install libmagic

On Windows:

Use python-magic-bin instead of python-magic for easier installation.

🛠️ Dependencies

  • PyMuPDF (fitz)

  • beautifulsoup4

  • python-docx

  • python-pptx

  • odfpy

  • openpyxl

  • lxml

  • xlrd (<2.0.0)

  • python-magic

Dependencies are automatically installed from pyproject.toml.

📚 Usage Example

Extract text from a file path:

from pyxtxt import xtxt

text = xtxt("document.pdf")
print(text)

Extract text from a file-like buffer:

import io

with open("document.docx", "rb") as f:
    buffer = io.BytesIO(f.read())

from pyxtxt import xtxt
text = xtxt(buffer)
print(text)

Show available formats: from pyxtxt import extxt_available_formats

from pyxtxt import extxt_available_formats
text = extxt_available_formats()
print(text)
# For a pretty printing
text = extxt_available_formats(True)
print(text)

⚠️ Known Limitations

When passing a raw stream (io.BytesIO) without a filename, legacy files (.doc, .xls, .ppt) may not be correctly detected.

This is a limitation of libmagic beacuse the signature byte sequence at the start of doc/xls/ppt is exactly the same (b'\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1'), not of pyxtxt.

If available, using the original filename is highly recommended.

To extract text from documents in MSWrite's old .doc format, it is necessary to install antiword.

sudo apt-get update
sudo apt-get -y install antiword

🔒 License

Distributed under the MIT License.

The software is provided "as is" without any warranty of any kind.

Pull requests, issues, and feedback are warmly welcome! 🚀

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

pyxtxt-0.1.22.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

pyxtxt-0.1.22-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file pyxtxt-0.1.22.tar.gz.

File metadata

  • Download URL: pyxtxt-0.1.22.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyxtxt-0.1.22.tar.gz
Algorithm Hash digest
SHA256 1ae7538fc0894b473567e4809309400b3d89b35443be8407165c58d84761c6cc
MD5 97d62d6256dd312274f5ba2e14be6849
BLAKE2b-256 989cac3c54249de1a63e30a6bfe06d93cdcf5b3c50c6ed5cc1d0dc6d03d32211

See more details on using hashes here.

File details

Details for the file pyxtxt-0.1.22-py3-none-any.whl.

File metadata

  • Download URL: pyxtxt-0.1.22-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyxtxt-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 e1a7ca65d673e454765d6f2fdecd33f91a83f5d3548971cce0870cab72ce039c
MD5 ed4d7c8dea0fcbf0e4389788ec84ac06
BLAKE2b-256 f709034078cbabc3cbab6a6e033afdaa36cff97d837d6537a62790b7309b9f7c

See more details on using hashes here.

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