Blog

Convert documents to Markdown from the CLI or Python

10 Aug 2026 · 4 min read


If you're doing AI/ML work, you probably have a mix of document formats scattered across your datasets: PDF research papers, DOCX manuscripts, PPTX presentations, XLSX spreadsheets, EPUB ebooks. Before you can use any of them for training, fine-tuning, or RAG, they need to be normalised into clean, structured text.

This post shows how to use AnyMD from the command line and from Python to convert any document format to Markdown in one step — no format-specific parsers, no fallbacks, no cleanup.

From the command line

The simplest usage — convert a single file:

curl https://anymd.net/api/convert \
  -H "Authorization: Bearer your-key" \
  -F "file=@paper.pdf"

That's it. AnyMD auto-detects the format from the file extension. Same command works for DOCX, PPTX, XLSX, RTF, EPUB, ODT, HTML, CSV, and more.

Pipe the output to a file:

curl -s https://anymd.net/api/convert \
  -H "Authorization: Bearer your-key" \
  -F "file=@research-paper.pdf" \
  -o research-paper.md

From Python

import requests

with open("report.pdf", "rb") as f:
    resp = requests.post(
        "https://anymd.net/api/convert",
        headers={"Authorization": "Bearer your-key"},
        files={"file": ("report.pdf", f)},
    )
    markdown = resp.text
    print(markdown[:500])

Batch conversion for training data prep

import requests
from pathlib import Path

markdown_dir = Path("training_data_md")
markdown_dir.mkdir(exist_ok=True)

for doc in Path("raw_documents").glob("*"):
    if doc.suffix not in {".pdf", ".docx", ".pptx", ".xlsx", ".epub"}:
        continue
    with open(doc, "rb") as f:
        resp = requests.post(
            "https://anymd.net/api/convert",
            headers={"Authorization": "Bearer your-key"},
            files={"file": (doc.name, f)},
        )
        if resp.ok:
            out = markdown_dir / f"{doc.stem}.md"
            out.write_text(resp.text)
            print(f"✓ {doc.name} → {out.name}")
        else:
            print(f"✗ {doc.name}: {resp.status_code}")

That's all the code you need to normalise a mixed-format document library into clean, consistent Markdown — ready for chunking, embedding, or fine-tuning.

Why not use format-specific libraries?

Most projects start with PyMuPDF for PDFs, python-pptx for PowerPoint, python-docx for Word, openpyxl for Excel, and ebooklib for EPUBs. That's five different libraries with five different APIs, five different output formats, and five different maintenance burdens.

AnyMD is one API, one output format (GFM Markdown), and one authentication key. No library management, no version conflicts, no format-specific edge cases to debug.

Get your free API key — 100 pages/month, no card required.


← Read more →