File Format Processing

Libraries for parsing and manipulating specific file formats.

PDFs you merge, split, or encrypt need only pypdf. Which Python file format library you need beyond that depends on whether you read a file or create it.

How to choose:

Listed in editorial order, grouped by use case. Click a column header to re-sort the whole list.

Press / to search. Tags open their category. Click a row for details.

Search and filter

Results

Row number Tags

General 2 projects

Parsing and analyzing ELF files and DWARF debugging information.
eliben/github.com/eliben/pyelftools /2,290 stars /
A module for tabular datasets in XLS, CSV, JSON, YAML.
jazzband/github.com/jazzband/tablib /4,759 stars /

File Conversion 3 projects

Python tool for converting files and office documents to Markdown.
microsoft/github.com/microsoft/markitdown /192,898 stars /
A thin wrapper for pandoc, the universal document converter.
Library for converting documents into structured data.

Excel 2 projects

A library for reading and writing Excel 2010 xlsx/xlsm/xltx/xltm files.
A Python module for creating Excel .xlsx files.
jmcnamara/github.com/jmcnamara/XlsxWriter /3,990 stars /

Word 1 project

Creates, reads, and updates Microsoft Word (.docx) files.

PowerPoint 1 project

Python library for creating and updating PowerPoint (.pptx) files.
scanny/github.com/scanny/python-pptx /3,570 stars /

PDF 4 projects

A library capable of splitting, merging, cropping, and transforming PDF pages.
py-pdf/github.com/py-pdf/pypdf /10,279 stars /
A fast MuPDF-based library for extracting, rendering, and editing PDFs and other documents.
pymupdf/github.com/pymupdf/PyMuPDF /11,015 stars /
An open-source library for generating PDFs and graphics.
A community-maintained fork of PDFMiner for extracting information from PDF documents.
pdfminer/github.com/pdfminer/pdfminer.six /7,047 stars /

HTML-to-PDF 1 project

A visual rendering engine for HTML and CSS that can export to PDF.
Kozea/github.com/Kozea/WeasyPrint /9,740 stars /

Markdown 3 projects

Markdown parser with 100% CommonMark support, extensions, and syntax plugins.
A Python implementation of John Gruber's Markdown.
A fast yet powerful Python Markdown parser with renderers and plugins.
lepture/github.com/lepture/mistune /3,080 stars /

Data Formats 2 projects

(Python standard library) Parse TOML files.
A full-featured YAML framework for Python.
yaml/github.com/yaml/pyyaml /2,964 stars /

File Format Processing guide

pypdf is a pure-Python PDF library for splitting, merging, cropping, and transforming pages, and it adds passwords too. To merge files, append() each one to a PdfWriter and write it out. With no C dependency, it's easy to install, but it doesn't generate new PDFs. It reads text with page.extract_text(), while a scanned page needs OCR software.

pyelftools parses ELF files and DWARF debug info in pure Python. Pass an open file to ELFFile, its main entry point, and stay on the high-level API: its guide says to use the low-level structs at your own peril.

Tablib is a format-agnostic tabular dataset library. Dataset().load(fh) detects the format of the file you load, and export() writes the same data as CSV, JSON, or another format.

MarkItDown converts PDF, Word, Excel, PowerPoint, HTML, and more into Markdown for LLMs and text analysis. Its README says it may not be the best option for high-fidelity conversions that people read. Don't pass untrusted input straight to it, and when you only read local files, call convert_local() instead of convert(), which also fetches URLs.

Docling is for documents where layout matters: it understands page layout, reading order, and tables, and runs OCR on scanned PDFs. It converts each file into a DoclingDocument, which you export to Markdown.

pypandoc wraps pandoc, which converts between Markdown, Word, LaTeX, HTML, and many other formats in both directions. It needs pandoc on your machine, and the pypandoc_binary package includes it. Pass a path to convert_file(), or a string and its format to convert_text(). For output formats like DOCX and EPUB, pass an outputfile, since that's the only way to convert to them.

openpyxl reads and writes Excel workbooks, so it's the one to use when the file already exists. Install defusedxml when you open spreadsheets from other people, since openpyxl doesn't guard against XML attacks by default.

XlsxWriter can't read or modify existing files. In return, it supports more Excel features than the alternatives, and its files are close to what Excel itself writes.

python-docx works on .docx files, not the older .doc. Start from a document that holds your styles, headers, and footers, and open it with Document('template.docx'): python-docx can only use a style that the starting document defines.

python-pptx creates and updates PowerPoint files. A deck's look comes from its theme, slide master, and layouts, so open a template deck with Presentation('template.pptx'). Add slides from its layouts and fill their placeholders, which carry the template's formatting.

PyMuPDF is a high-performance library for extracting, converting, and editing PDFs and other documents, built on MuPDF, and it also renders pages to images. It's available under the AGPL or a commercial license. For reading text and editing pages without that condition, use pypdf or pdfminer.six.

ReportLab creates PDFs directly from Python, like reports generated on a web server, with charts and tables. Lay out documents with Platypus: create a document from a DocTemplate class and pass a list of flowables, such as paragraphs and tables, to its build() method.

pdfminer.six extracts text from a PDF's source, with the exact location, font, and color of each piece, but it can't write PDFs. The simplest start is extract_text().

WeasyPrint turns HTML and CSS into PDFs, like reports, invoices, and tickets, with a layout engine built for pagination instead of a browser engine. It runs no JavaScript. Call HTML(...).write_pdf(). If users supply the HTML or CSS, its docs say you'll need extra configuration against high memory use, endless renderings, and local file leaks.

markdown-it-py follows the CommonMark spec, and plugins add syntax or replace existing rules.

Python-Markdown implements John Gruber's original Markdown. It's not a CommonMark implementation, and its docs say to look elsewhere if you want one. Pick it for its extension API and bundled extensions, like tables, fenced code blocks, and a table of contents.

Mistune is a fast parser with renderers and plugins, compatible with "sane CommonMark rules".

tomllib comes with Python and parses TOML, but doesn't write it. With untrusted input, limit its size, since a malicious TOML string can use a lot of CPU and memory.

PyYAML parses and emits YAML. Load it with yaml.safe_load(), since yaml.load can call any Python function when the data comes from an untrusted source.

Markdown your users write can carry HTML, so give each parser its safe setting. With markdown-it-py, use the js-default preset, which its docs strongly recommend for user content in web apps. Python-Markdown doesn't sanitize its output, so run a sanitizer over the HTML. With Mistune, build your parser with mistune.create_markdown(), which escapes HTML, instead of mistune.html(), which doesn't.

Know a project that belongs here?

Tell us what it does and why it stands out.