DocumentConverter class is the abstract base class for all document converters in MarkItDown. Custom converters must inherit from this class and implement the accepts() and convert() methods.
Overview
A converter’s lifecycle consists of two phases:- Acceptance - The
accepts()method determines if the converter can handle a given file - Conversion - The
convert()method performs the actual conversion to Markdown
Methods
accepts()
BinaryIO
required
The file-like object to check. Must support
seek(), tell(), and read() methods.StreamInfo
required
Metadata about the file including mimetype, extension, charset, URL, and filename.
dict
Additional keyword arguments that may be used by the converter.
bool
Returns
True if the converter can handle this document, False otherwise.Important Notes
Decision Criteria
Theaccepts() method typically checks:
- Extension:
stream_info.extension(e.g.,.pdf,.docx) - MIME type:
stream_info.mimetype(e.g.,application/pdf) - URL:
stream_info.url(for site-specific converters like Wikipedia, YouTube) - Filename:
stream_info.filename(for well-known files likeDockerfile,Makefile) - File content: Read file signature/magic bytes (with position reset)
convert()
BinaryIO
required
The file-like object to convert. Must support
seek(), tell(), and read() methods.StreamInfo
required
Metadata about the file.
dict
Additional options for the converter. Common options include:
llm_client: LLM client for AI-powered conversionllm_model: Model name for LLMexiftool_path: Path to exiftool binaryurl: Source URL (deprecated, usestream_info.url)file_extension: File extension (deprecated, usestream_info.extension)
DocumentConverterResult
The conversion result containing the Markdown text and optional metadata.
Exceptions
Theconvert() method may raise:
FileConversionException- When the converter recognizes the format but conversion failsMissingDependencyException- When a required dependency is not installed- Other exceptions for unexpected errors
Creating a Custom Converter
Basic Example
Advanced Example with Content Inspection
URL-Based Converter
Registering Custom Converters
After creating a converter, register it with MarkItDown:Priority Guidelines
Choose the appropriate priority for your converter:PRIORITY_SPECIFIC_FILE_FORMAT(0.0) - For specific formats (.docx,.pdf) or specific sites (Wikipedia, GitHub)PRIORITY_GENERIC_FILE_FORMAT(10.0) - For catch-all converters (text/*, generic HTML)
Best Practices
Stream Position Management
Error Handling
Raise appropriate exceptions:Metadata Handling
Return complete metadata when available:See Also
- DocumentConverterResult - Return type for converters
- StreamInfo - File metadata passed to converters
- MarkItDown.register_converter() - Register custom converters