MarkItDown provides a comprehensive Python API for converting documents to Markdown programmatically.
Basic Usage
The simplest way to use MarkItDown:
Initialization
Default Initialization
With Plugins
Disable Built-in Converters
With Custom Configuration
Conversion Methods
convert()
The main conversion method accepts multiple input types:
convert_local()
Convert a local file:
convert_stream()
Convert from a binary stream:
convert_url() / convert_uri()
Convert from a URL:
convert_url() is an alias for convert_uri(). The convert_uri() method is preferred for new code.
convert_response()
Convert from a requests Response object:
StreamInfo
Provide metadata hints about the file being converted:
StreamInfo Fields
All fields are optional:
DocumentConverterResult
All conversion methods return a DocumentConverterResult object:
Configuration Options
LLM Integration for Image Descriptions
See the LLM Integration guide for details.
Azure Document Intelligence
With custom credential:
See the Azure Document Intelligence guide for details.
Specify the path to ExifTool for image metadata extraction:
DOCX Style Map
Customize DOCX conversion with a Mammoth style map:
Data URI Handling
Control whether data URIs are kept in the output:
Advanced: Custom Converters
Registering Custom Converters
Converter Priority
Error Handling
Complete Example
A comprehensive example combining multiple features: