Skip to main content

Convert documents (PDF, DOCX) to high-quality Markdown using Vision LLMs via LiteLLM

Project description

Markdownify

Mardownify is a super easy-to-use PDF to high-quality Markdown converter using Vision LLMs. It supports text, images, signatures, tables, charts, flowcharts and preserves document structure (Headings, numbered lists etc).

Tables become Markdown tables, charts become Mermaid diagrams, and images get concise summaries. Use as a CLI or Python library. Works with 100+ LLMs. Recommended to use with gpt-5-mini or gpt-4.1-mini or even better models for better performance.

Features

  • High-quality complex markdown generation powered by LLMs.
  • Supports Text, Images, Tables, Charts.
  • Built-in prompts tuned for clean Markdown, Mermaid, and structured headings along with ability to customise.
  • Supports multi-page tables, charts and images.
  • High-fidelity page rendering from PDF.
  • Optional DOCX→PDF conversion using MS word installation.
  • Works seamlessly with 100+ LLMs with LiteLLM Intergration.

Install

uv pip install llm-markdownify
# or
pip install llm-markdownify

Quickstart (CLI)

markdownify run input.pdf -o output.md --model gpt-5-mini

Python API (one-liner)

from llm_markdownify import convert

convert(
    "input.pdf",
    "output.md",
    model="gpt-5-mini",   # optional; can rely on env/provider defaults
    dpi=72,
    profile="contracts",    # or path to JSON profile
)

Optional DOCX support (macOS/Windows via Word):

pip install llm-markdownify[docx]

Configure your provider (via LiteLLM)

Pick one of the following. See the full providers list and details in the LiteLLM docs: Supported Providers.

  • OpenAI

    • Set your API key:
      export OPENAI_API_KEY="sk-..."
      
    • Example usage:
      markdownify run input.pdf -o output.md --model gpt-5-mini
      
  • Google Gemini

    • Set your API key (Google AI Studio key):
      export GOOGLE_API_KEY="..."
      
    • Example usage (pick a Gemini vision-capable model):
      markdownify run input.pdf -o output.md --model gemini/gemini-2.5-flash
      
  • Azure OpenAI

    • Set these environment variables (values from your Azure OpenAI resource):
      export AZURE_API_KEY="..."
      export AZURE_API_BASE="https://<your-resource>.openai.azure.com"
      export AZURE_API_VERSION=""
      
    • Use your deployment name via the azure/<deployment_name> model syntax:
      markdownify run input.pdf -o output.md --model azure/<deployment_name>
      
    • See: LiteLLM Azure OpenAI
  • OpenAI-compatible APIs

    • Many providers expose an OpenAI-compatible REST API. Set your API key and base URL:
      export OPENAI_API_KEY="..."
      export OPENAI_API_BASE="https://your-openai-compatible-endpoint.com/v1"
      
    • Use the model name supported by that endpoint:
      markdownify run input.pdf -o output.md --model <model-name>
      
    • Reference: LiteLLM Providers

For additional providers and advanced configuration (fallbacks, cost tracking, streaming), see the LiteLLM docs: Getting Started.

Configuration flags

  • --model: LiteLLM model (e.g., gpt-5-mini, azure/<deployment>, gemini/gemini-2.5-flash)
  • --dpi: Render DPI (default 72)
  • --max-group-pages: Max pages to merge for continued content (default 3)
  • --no-grouping: Disable LLM-based grouping
  • --temperature, --max-tokens: LLM generation params

Dev tooling

  • Install pre-commit and enable the license header hook:
    pip install pre-commit
    pre-commit install
    # run on all files once
    pre-commit run --all-files
    
    This inserts the header:
    # Copyright (c) 2025 Sethu Pavan Venkata Reddy Pastula
    # Licensed under the Apache License, Version 2.0. See LICENSE file for details.
    # SPDX-License-Identifier: Apache-2.0
    

Attribution & License

This project uses the Apache 2.0 License, which includes an attribution/NOTICE requirement. If you distribute or use this project, please keep the LICENSE and NOTICE files intact, crediting the original author, Sethu Pavan Venkata Reddy Pastula.

Development

  • Requires Python 3.10+
  • Use uv for fast installs: uv sync
  • Run tests: pytest
  • Lint: ruff check src tests

Releasing

GitHub Actions are configured to:

  • Run tests on PRs/pushes
  • Build & publish to PyPI on tagged releases (requires PYPI_API_TOKEN secret)

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

llm_markdownify-0.1.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

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

llm_markdownify-0.1.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file llm_markdownify-0.1.0.tar.gz.

File metadata

  • Download URL: llm_markdownify-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llm_markdownify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd27872b52cd1549362e9845330923e8548976f56e722a2d4afb05c7a4c57aac
MD5 70a1802c33d3bec4038efb21780db9ed
BLAKE2b-256 811477843a0de2b356bf1d8a4e6418966f183565c397907f2e8014c12e2bca18

See more details on using hashes here.

File details

Details for the file llm_markdownify-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_markdownify-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cffef5dc51cd1d89495cc5e5c1321153f8a11eb8cba0bbc7afb09d208cdc34c
MD5 c0ec8d97c974acdb8769955d55f51a97
BLAKE2b-256 f2c78ff2c9feceba09d92d6aecabbe27bf7d348fa6f4cc7111863762dca4f131

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