markitdown README

The project's README from github.com/microsoft/markitdown. As one markdown file: README.md.

MarkItDown

PyPI PyPI - Downloads

[!IMPORTANT] MarkItDown performs I/O with the privileges of the current process. Like open() or requests.get(), it will access resources that the process itself can access. Sanitize your inputs in untrusted environments, and call the narrowest convert_* function needed for your use case (e.g., convert_stream(), or convert_local()). See the Security Considerations section of the documentation for more information.

MarkItDown is a lightweight Python utility for converting various files to Markdown for use with LLMs and related text analysis pipelines. To this end, it is most comparable to textract, but with a focus on preserving important document structure and content as Markdown (including: headings, lists, tables, links, etc.) While the output is often reasonably presentable and human-friendly, it is meant to be consumed by text analysis tools -- and may not be the best option for high-fidelity document conversions for human consumption.

MarkItDown currently supports the conversion from:

Why Markdown?

Markdown is extremely close to plain text, with minimal markup or formatting, but still provides a way to represent important document structure. Mainstream LLMs, such as OpenAI's GPT-4o, natively "speak" Markdown, and often incorporate Markdown into their responses unprompted. This suggests that they have been trained on vast amounts of Markdown-formatted text, and understand it well. As a side benefit, Markdown conventions are also highly token-efficient.

Prerequisites

MarkItDown requires Python 3.10 or higher. It is recommended to use a virtual environment to avoid dependency conflicts.

With the standard Python installation, you can create and activate a virtual environment using the following commands:

python -m venv .venv
source .venv/bin/activate

If using uv, you can create a virtual environment with:

uv venv --python=3.12 .venv
source .venv/bin/activate
# NOTE: Be sure to use 'uv pip install' rather than just 'pip install' to install packages in this virtual environment

If you are using Anaconda, you can create a virtual environment with:

conda create -n markitdown python=3.12
conda activate markitdown

Installation

To install MarkItDown, use pip: pip install 'markitdown[all]'. Alternatively, you can install it from the source:

git clone [email protected]:microsoft/markitdown.git
cd markitdown
pip install -e 'packages/markitdown[all]'

Usage

Command-Line

markitdown path-to-file.pdf > document.md

Or use -o to specify the output file:

markitdown path-to-file.pdf -o document.md

You can also pipe content:

cat path-to-file.pdf | markitdown

Optional Dependencies

MarkItDown has optional dependencies for activating various file formats. Earlier in this document, we installed all optional dependencies with the [all] option. However, you can also install them individually for more control. For example:

pip install 'markitdown[pdf, docx, pptx]'

will install only the dependencies for PDF, DOCX, and PPTX files.

At the moment, the following optional dependencies are available:

Plugins

MarkItDown also supports 3rd-party plugins. Plugins are disabled by default. To list installed plugins:

markitdown --list-plugins

To enable plugins use:

markitdown --use-plugins path-to-file.pdf

To find available plugins, search GitHub for the hashtag #markitdown-plugin. To develop a plugin, see packages/markitdown-sample-plugin.

markitdown-ocr Plugin

The markitdown-ocr plugin adds OCR support to PDF, DOCX, PPTX, and XLSX converters, extracting text from embedded images using LLM Vision — the same llm_client / llm_model pattern that MarkItDown already uses for image descriptions. No new ML libraries or binary dependencies required.

Installation:

pip install markitdown-ocr
pip install openai  # or any OpenAI-compatible client

Usage:

Pass the same llm_client and llm_model you would use for image descriptions:

from markitdown import MarkItDown
from openai import OpenAI

md = MarkItDown(
    enable_plugins=True,
    llm_client=OpenAI(),
    llm_model="gpt-4o",
)
result = md.convert("document_with_images.pdf")
print(result.markdown)

If no llm_client is provided the plugin still loads, but OCR is silently skipped and the standard built-in converter is used instead.

See packages/markitdown-ocr/README.md for detailed documentation.

Azure Content Understanding

Azure Content Understanding provides higher-quality conversion with structured field extraction (YAML front matter), multi-modal support (documents, images, audio, video), and configurable analyzers.

Install: pip install 'markitdown[az-content-understanding]'

When to use Content Understanding

Content Understanding is ideal when you need capabilities beyond what built-in or Document Intelligence converters provide:

Capability Built-in converters Azure Document Intelligence Azure Content Understanding
Document conversion Offline, format-specific extraction Cloud layout extraction Cloud multimodal extraction
Structured fields Not available Not exposed by this integration YAML front matter from analyzer fields
Custom analyzers Not available Not configurable in this integration Supported with cu_analyzer_id
Audio and video Basic audio, no video Not supported Audio and video analyzers
Cost Local compute only Billable Azure API calls Billable Azure API calls

CLI:

markitdown path-to-file.pdf --use-cu --cu-endpoint "<content_understanding_endpoint>"

The endpoint can also be set once in the environment, so callers only need --use-cu:

export MARKITDOWN_CU_ENDPOINT="<content_understanding_endpoint>"
markitdown path-to-file.pdf --use-cu

Python API:

from markitdown import MarkItDown

# Zero-config — auto-selects analyzer per file type
md = MarkItDown(cu_endpoint="<content_understanding_endpoint>")
result = md.convert("report.pdf")   # documents → prebuilt-documentSearch
result = md.convert("meeting.mp4")  # video → prebuilt-videoSearch
result = md.convert("call.wav")     # audio → prebuilt-audioSearch
print(result.markdown)

With a custom analyzer (for domain-specific field extraction):

md = MarkItDown(
    cu_endpoint="<content_understanding_endpoint>",
    cu_analyzer_id="my-invoice-analyzer",
)
result = md.convert("invoice.pdf")
print(result.markdown)
# Output includes YAML front matter with extracted fields:
# ---
# contentType: document
# fields:
#   VendorName: CONTOSO LTD.
#   InvoiceDate: '2019-11-15'
# ---
# <!-- page 1 -->
# ...

When cu_analyzer_id is set, the converter automatically scopes it to compatible file types based on the analyzer's modality. Incompatible types (e.g., audio files with a document analyzer) auto-route to default prebuilt analyzers.

Cost note: Each convert() call for a CU-routed format is a billable Azure API call. Use cu_file_types to restrict which formats route to CU:

from markitdown.converters import ContentUnderstandingFileType

md = MarkItDown(
    cu_endpoint="<content_understanding_endpoint>",
    cu_file_types=[ContentUnderstandingFileType.PDF],  # only PDFs use CU
)

More information about Azure Content Understanding can be found here.

Azure Document Intelligence

To use Microsoft Document Intelligence for conversion:

markitdown path-to-file.pdf -o document.md -d -e "<document_intelligence_endpoint>"

The endpoint can also be set once in the environment, so callers only need -d:

export MARKITDOWN_DOCINTEL_ENDPOINT="<document_intelligence_endpoint>"
markitdown path-to-file.pdf -o document.md -d

More information about how to set up an Azure Document Intelligence Resource can be found here

Python API

Basic usage in Python:

from markitdown import MarkItDown

md = MarkItDown(enable_plugins=False) # Set to True to enable plugins
result = md.convert("test.xlsx")
print(result.markdown)

Document Intelligence conversion in Python:

from markitdown import MarkItDown

md = MarkItDown(docintel_endpoint="<document_intelligence_endpoint>")
result = md.convert("test.pdf")
print(result.markdown)

To use Large Language Models for image descriptions (currently only for pptx and image files), provide llm_client and llm_model:

from markitdown import MarkItDown
from openai import OpenAI

client = OpenAI()
md = MarkItDown(llm_client=client, llm_model="gpt-4o", llm_prompt="optional custom prompt")
result = md.convert("example.jpg")
print(result.markdown)

Docker

docker build -t markitdown:latest .
docker run --rm -i markitdown:latest < ~/your-file.pdf > output.md

Contributing

Before starting significant work, please read What to Contribute, which describes what is in and out of scope for this repository.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

What to Contribute

MarkItDown is a Python utility for converting files to Markdown for use with LLMs and related text analysis pipelines. This repository is intended to provide Python libraries that can be incorporated into other systems — not the end-user applications built on top of them.

In scope

Out of scope

We cannot accept additional applications, services, or servers. This includes:

Projects like these are genuinely useful, and we would rather see them thrive than be turned away. If you are interested in providing a web service, API, or graphical application for MarkItDown, please maintain it as a separate package or project that depends on markitdown from PyPI.

Extending MarkItDown Without Changing This Repository

MarkItDown supports 3rd-party plugins, so support for a new format can be published and installed independently of this repository:

markitdown --list-plugins
markitdown --use-plugins path-to-file.pdf

See packages/markitdown-sample-plugin to get started, and tag your repository #markitdown-plugin so that others can find it.

How to Contribute

You can help by looking at issues or helping review PRs. We have also marked some issues as 'open for contribution' and PRs as 'open for reviewing' to help facilitate community contributions. These labels are suggestions; contributions within the scope described above are welcome.

All Especially Needs Help from Community
Issues All Issues Issues open for contribution
PRs All PRs PRs open for reviewing

Running Tests and Checks

Security Considerations

MarkItDown performs I/O with the privileges of the current process. Like open() or requests.get(), it will access resources that the process itself can access.

Sanitize your inputs: Do not pass untrusted input directly to MarkItDown. If any part of the input may be controlled by an untrusted user or system, such as in hosted or server-side applications, it must be validated and restricted before calling MarkItDown. Depending on your environment, this may include restricting file paths, limiting URI schemes and network destinations, and blocking access to private, loopback, link-local, or metadata-service addresses.

Call only the conversion method you need: Prefer the narrowest conversion API that fits your use case. MarkItDown's convert() method is intentionally permissive and can handle local files, remote URIs, and byte streams. If your application only needs to read local files, call convert_local() instead. If you need more control over URI fetching, call requests.get() yourself and pass the response object to convert_response(). For maximum control, open a stream to the input you want converted and call convert_stream().

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

markitdown (microsoft/markitdown)

Searching Database…

190.7K ·GitHub
这是什么?MarkItDown 是一个轻量级的 Python 工具,可以把 PDF、PowerPoint、Word、Excel、图片、音频、HTML、CSV/JSON/XML、ZIP 压缩包、EPub 电子书,甚至 YouTube 链接转换成 Markdown,目的是把文档输入到大语言模型(LLM)和文本分析流程中。
这是 Python 库还是命令行工具?两者都是:它既可以作为 Python 库导入使用,也可以作为 'markitdown' 命令行工具使用,还提供一个单独的 'markitdown-mcp' 包,以 MCP 服务器的形式对外提供服务。
怎么安装并开始转换文件?使用 pip install 'markitdown[all]' 安装(需要 Python 3.10+),然后运行 markitdown yourfile.pdf,或者把内容通过管道传给它;也提供 Docker 镜像。
处理特定格式的文件需要额外安装软件包吗?需要。每种格式都有各自的可选依赖组,例如 [pptx]、[docx]、[xlsx]、[pdf]、[outlook]、[az-doc-intel]、[audio-transcription] 或 [youtube-transcription];安装 [all] 则会一次性装上所有转换器的依赖。
在服务器上处理不可信的输入,安全吗?默认不安全。MarkItDown 以调用它的进程相同的权限执行 I/O 操作,因此在托管或服务器端使用时,必须在转换前对不可信的文件路径或 URL 进行清理和限制。
markitdown-ocr 插件会增加什么功能?这是一个可选的第三方插件,它会把文档中嵌入的图片发送给你自己提供的大语言模型视觉模型,从而为 PDF、DOCX、PPTX 和 XLSX 转换器加上 OCR 功能,而且不需要额外的机器学习库或二进制依赖。
Azure Content Understanding 和 Azure Document Intelligence 在这里有什么区别?Content Understanding 会以 YAML front matter(文件开头的 YAML 元数据块)的形式添加结构化字段提取结果,并支持音频和视频,而内置转换器和 Document Intelligence 集成都无法处理这类内容。Document Intelligence 则只专注于仅针对文档、质量更高的云端版面提取。
作者为什么选择 Markdown 作为输出格式?Markdown 接近纯文本,同时能保留标题、列表和表格等结构;而 GPT-4o 等主流大语言模型在大量 Markdown 内容上训练过,因此能自然地解析和生成它,也更节省 token。
MarkItDown 默认不支持的格式,我能自己加吗?可以。新的格式支持可以作为第三方插件发布,无需修改本仓库;插件默认是禁用的,你可以在 GitHub 上搜索话题标签 #markitdown-plugin 来找到它们。
What are similar projects?docling, marker, zerox, unstructured, PyMuPDF, kotaemon, MinerU, langfuse
Creator
microsoft
Size
5.7 MB
Stars
190.7K
Age
1y
Commits · 90 Days