fix: match ExifTool directories case-insensitively on Windows (#2837)
ExifTool auto discovery accepts the path from shutil.which only when its directory equals one of the trusted directories. shutil.which keeps the spelling of the PATH entry, and the default Windows PATH spells System32 as C:\WINDOWS\system32, so the exact comparison against C:\Windows\System32 fails and image and audio metadata are silently dropped.
Compare os.path.normcase of both sides. normcase is the identity on POSIX, so Linux and macOS matching is unchanged; the candidate already goes through abspath, which normalizes separators.
Co-authored-by: Adam Fourney adamfo@microsoft.com
GitHub上的Microsoft 官方版本:用于将文件和 Office 文档转换为 Markdown 的 Python 工具。
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
MarkItDown
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:
NOTE: Image captioning and speech transcription rely on web-hosted services.
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 through 3.14. 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:
If using
uv, you can create a virtual environment with:If you are using Anaconda, you can create a virtual environment with:
Installation
To install MarkItDown, use pip:
pip install 'markitdown[all]'. Alternatively, you can install it from the source:Usage
Command-Line
Or use
-oto specify the output file:You can also pipe content:
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:will install only the dependencies for PDF, DOCX, and PPTX files.
At the moment, the following optional dependencies are available:
[all]Installs all optional dependencies[pptx]Installs dependencies for PowerPoint files[docx]Installs dependencies for Word files[xlsx]Installs dependencies for Excel files[xls]Installs dependencies for older Excel files[pdf]Installs dependencies for PDF files[outlook]Installs dependencies for Outlook messages[az-doc-intel]Installs dependencies for Azure Document Intelligence[az-content-understanding]Installs dependencies for Azure Content Understanding[audio-transcription]Installs dependencies for audio transcription of wav and mp3 files[youtube-transcription]Installs dependencies for fetching YouTube video transcriptionPlugins
MarkItDown also supports 3rd-party plugins. Plugins are disabled by default. To list installed plugins:
To enable plugins use:
To find available plugins, search GitHub for the hashtag
#markitdown-plugin. To develop a plugin, seepackages/markitdown-sample-plugin.markitdown-ocr Plugin
The
markitdown-ocrplugin adds OCR support to PDF, DOCX, PPTX, and XLSX converters, extracting text from embedded images using LLM Vision — the samellm_client/llm_modelpattern that MarkItDown already uses for image descriptions. No new ML libraries or binary dependencies required.Installation:
Usage:
Pass the same
llm_clientandllm_modelyou would use for image descriptions:If no
llm_clientis provided the plugin still loads, but OCR is silently skipped and the standard built-in converter is used instead.See
packages/markitdown-ocr/README.mdfor 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:
cu_endpointhandles documents, images, audio, and video with automatic analyzer routing.docintel_model_idcu_analyzer_idCLI:
The endpoint can also be set once in the environment, so callers only need
--use-cu:Python API:
With a custom analyzer (for domain-specific field extraction):
When
cu_analyzer_idis 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. Usecu_file_typesto restrict which formats route to CU:More information about Azure Content Understanding can be found here.
Azure Document Intelligence
To use Microsoft Document Intelligence for conversion:
The endpoint can also be set once in the environment, so callers only need
-d:If
AZURE_API_KEYis not set, MarkItDown usesDefaultAzureCredential.Select a model, configure analysis add-ons, or request fields from the CLI:
No analysis add-ons are enabled by default. Use
--docintel-featuresto opt in, or--docintel-features noneto explicitly request no add-ons. Analysis add-ons and query fields apply only to OCR-supported inputs such as PDFs and images.Available feature values are
barcodes,formulas,keyValuePairs,languages,ocrHighResolution, andstyleFont. Theformulas,ocrHighResolution, andstyleFontfeatures incur additional charges, as does thequeryFieldsadd-on, which is priced differently from the other add-ons. See the Document Intelligence add-on documentation and pricing for details.More information about how to set up an Azure Document Intelligence Resource can be found here
Python API
Basic usage in Python:
Document Intelligence conversion in Python using an API key:
Omit
docintel_credentialto useAZURE_API_KEYwhen it is set, orDefaultAzureCredentialotherwise.Configure the model, analysis add-ons, and structured query fields:
Omit
docintel_featuresor setdocintel_features=[]to request no analysis add-ons. When query fields are provided, MarkItDown automatically enables the requiredqueryFieldsadd-on. Models that return structured fields prepend them to the Markdown as YAML front matter. A single document uses a top-levelfieldsmapping. When the service returns multiple documents, the front matter instead contains adocumentslist in service order, with a separatefieldsmapping for each document. Documents without extracted fields retain an empty mapping in that list; no front matter is emitted when all documents have empty fields. Selection groups are represented as lists of selected values.To use Large Language Models for image descriptions (currently only for pptx and image files), provide
llm_clientandllm_model:max_retriescontrols the OpenAI client’s automatic retries for retryable errors (the default is 2);5allows up to six attempts with backoff. See the OpenAI SDK retry documentation.If any attempt succeeds, image conversion continues normally. If the client raises an error after exhausting its retries, or encounters a non-retryable error, MarkItDown tries other applicable converters and raises
FileConversionExceptiononly if none succeeds.Docker
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 opencode@microsoft.com 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
markitdowncommand-line interfacemarkitdown-mcppackageOut 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
markitdownfrom 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:
See
packages/markitdown-sample-pluginto get started, and tag your repository#markitdown-pluginso 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.
Running Tests and Checks
Navigate to the MarkItDown package:
Install
hatchin your environment and run tests:(Alternative) Use the Devcontainer which has all the dependencies installed:
Run pre-commit checks before submitting a PR:
pre-commit run --all-filesSecurity Considerations
MarkItDown performs I/O with the privileges of the current process. Like
open()orrequests.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, callconvert_local()instead. If you need more control over URI fetching, callrequests.get()yourself and pass the response object toconvert_response(). For maximum control, open a stream to the input you want converted and callconvert_stream().Additionally, image captioning, speech transcription, Azure Document Intelligence, and Azure Content Understanding rely on web-hosted services to function. For local-only operations, install only the optional dependencies that you need and want to use.
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.