
anydoc
Open Source Python Library for Document Conversion
Convert Word, Excel, PowerPoint, PDF, RTF, EPUB, CSV & ODF Files to Clean Markdown via Fast Python API.
What is anydoc?
anydoc is a high-performance, open-source Python library that converts documents from Word, Excel, PowerPoint, PDF, RTF, EPUB, CSV, and OpenDocument formats into clean, structured GitHub-Flavored Markdown. Built on Rust for speed and reliability, it delivers consistent output regardless of input format, making it ideal for LLM ingestion, content migration, and document processing pipelines. The library supports format detection from file content, embedded assets handling, and optional hosted OCR for scanned PDFs via Firecrawl Parse.
With one-liner conversion functions, anydoc eliminates format-specific complexity by normalizing all supported document types into a shared document model before rendering Markdown. It powers Firecrawl Parse and is optimized for low latency—median conversion times are under 5ms per document. Developers can integrate it via Python, Node.js, Rust, or WebAssembly, and benefit from robust error handling, full document structure preservation (tables, headings, footnotes, equations), and zero external dependencies for local conversions.
Getting Started with anydoc
Install anydoc via pip to begin converting documents to Markdown in Python. The library is available on PyPI as `firecrawl-anydoc` and works with Python 3.7+. For the fastest experience, it uses precompiled Rust binaries. You can also explore the source code and contribute on [anydoc GitHub](https://github.com/firecrawl/anydoc). The library supports CLI, Node.js, Rust, and WebAssembly, but Python users benefit from a simple, intuitive API with optional OCR integration via Firecrawl Parse.
Install anydoc via PIP
pip install firecrawl-anydocConvert Documents to Markdown
anydoc provides a simple and consistent API to convert documents from various formats into clean Markdown. You can convert from file paths, raw bytes, or even stdin, and the library automatically detects the format from content. It supports optional OCR for scanned PDFs using Firecrawl Parse, and returns structured output with embedded assets. The conversion preserves document structure including headings, tables, lists, footnotes, and equations rendered as LaTeX. This makes anydoc ideal for building document processing pipelines, LLM data ingestion, and content migration tools.
How to Convert a Word Document to Markdown via Python?
import anydoc
# Convert a Word document to Markdown
markdown = anydoc.to_markdown("report.docx")
# Enable hosted OCR for scanned PDFs
markdown = anydoc.to_markdown("scan.pdf", ocr="hosted")
# Convert from bytes with format detection
markdown = anydoc.to_markdown_bytes(data)
# Specify format for signature-less files like CSV
markdown = anydoc.to_markdown_bytes(data, "csv")OCR for Scanned PDFs
anydoc processes text-based PDFs locally but returns a `NeedsOcr` error for scanned or image-only pages. To handle such documents, you can opt into hosted OCR via Firecrawl Parse—no signup required. When enabled, the entire document is sent to Parse, which performs OCR and returns the same Markdown output. This ensures consistent processing regardless of input quality. You can configure the OCR mode (`auto`, `fast`, `ocr`) and API endpoint using environment variables or function parameters, giving you full control over the conversion pipeline while keeping sensitive data on-premise for non-scanned files.
How to Enable OCR for Scanned PDFs via Python?
import anydoc
# Convert a scanned PDF with hosted OCR
markdown = anydoc.to_markdown("scanned_report.pdf", ocr="hosted")
# Use custom API key for higher limits
markdown = anydoc.to_markdown("scanned_report.pdf", ocr="hosted", api_key="your-api-key")
# Or set FIRECRAWL_API_KEY environment variable for automatic usePreserve Document Structure
anydoc maintains full document structure during conversion, including headings with anchors, bold/italic/strikethrough, inline code, code blocks, links, internal cross-references, and complex lists (bulleted, numbered, nested, task). Tables with merged cells and header rows, block quotes, footnotes, endnotes, and speaker notes are all preserved. Equations from Word (OMML), OpenDocument (MathML), RTF, and EPUB are converted to GitHub-flavored LaTeX: `$...$` for inline and `$$...$$` for block equations. This ensures high-fidelity Markdown suitable for documentation, publishing, and LLM training datasets.
How to Extract Document Model with Embedded Assets?
import anydoc
# Get the full document model with embedded assets
document = anydoc.to_document("report.docx")
# Access embedded images and objects
for asset in document.assets:
print(f"Asset type: {asset.media_type}, size: {len(asset.data)} bytes")
# Render Markdown with assets referenced by alt text
markdown_with_assets = document.to_markdown()Content-Based Format Detection
anydoc reads document format directly from file content using standardized markers—PDF headers, RTF open groups, OLE stream names, ZIP package mimetypes—ensuring correct parsing even for mislabeled files. For formats without content markers like CSV, you can specify the format explicitly or rely on file extension detection. This robust detection mechanism eliminates guesswork and improves reliability in production environments where file extensions may be unreliable or missing. The same detection logic is available across Python, Node.js, Rust, and WebAssembly bindings for consistent behavior.
How to Detect Document Format from Bytes in Python?
import anydoc
# Detect format from raw bytes
format_type = anydoc.format_from_bytes(bytes_data)
# Or detect from file path
format_from_path = anydoc.format_from_path("document.xlsx")
# Use detected format for conversion (optional)
markdown = anydoc.to_markdown_bytes(bytes_data, format_type)