Skill Tracer
Skills › Scientific Agent Skills › markitdown › api_reference.md

api_reference.md

418 lines · skills/markitdown/references/api_reference.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# MarkItDown 0.1.8 API Reference
2
3Verified against the `v0.1.8` source tag and installed package on October 1, 2026.
4

MarkItDown 0.1.8 API Reference

Verified against the v0.1.8 source tag and installed package on October 1, 2026.

Raw lines 1 to 4
5## Public Imports
6
7```python
8from markitdown import (
9 DocumentConverter,
10 DocumentConverterResult,
11 FileConversionException,
12 MarkItDown,
13 MissingDependencyException,
14 PRIORITY_GENERIC_FILE_FORMAT,
15 PRIORITY_SPECIFIC_FILE_FORMAT,
16 StreamInfo,
17 UnsupportedFormatException,
19```
21Azure file-type enums are exported from `markitdown.converters`:
23```python
24from markitdown.converters import (
25 ContentUnderstandingFileType,
26 DocumentIntelligenceFileType,
28```

Public Imports

from markitdown import (
    DocumentConverter,
    DocumentConverterResult,
    FileConversionException,
    MarkItDown,
    MissingDependencyException,
    PRIORITY_GENERIC_FILE_FORMAT,
    PRIORITY_SPECIFIC_FILE_FORMAT,
    StreamInfo,
    UnsupportedFormatException,
)

Azure file-type enums are exported from markitdown.converters:

from markitdown.converters import (
    ContentUnderstandingFileType,
    DocumentIntelligenceFileType,
)
Raw lines 5 to 29
30## `MarkItDown`
32### Constructor
34```python
35MarkItDown(
36 *,
37 enable_builtins: bool | None = None,
38 enable_plugins: bool | None = None,
39 **kwargs,
41```
43Built-in converters are enabled by default. Third-party plugins are disabled by default.
45Recognized constructor keywords include:
47| Keyword | Purpose |
48|---|---|
49| `requests_session` | Custom `requests.Session` used by HTTP(S) URI conversion |
50| `llm_client` | OpenAI-compatible client for image descriptions and compatible plugins |
51| `llm_model` | Provider-specific model identifier |
52| `llm_prompt` | Prompt for image description/OCR |
53| `exiftool_path` | Explicit trusted ExifTool executable |
54| `style_map` | Mammoth style map for DOCX conversion |
55| `docintel_endpoint` | Enable Azure Document Intelligence |
56| `docintel_credential` | Explicit `AzureKeyCredential` or token credential |
57| `docintel_file_types` | Restrict Document Intelligence routing |
58| `docintel_api_version` | Azure Document Intelligence API version |
59| `cu_endpoint` | Enable Azure Content Understanding |
60| `cu_credential` | Explicit `AzureKeyCredential` or token credential |
61| `cu_analyzer_id` | Custom Content Understanding analyzer |
62| `cu_file_types` | Restrict Content Understanding routing |
64The public signature uses `**kwargs`; spell these names exactly. Unknown names can be silently ignored: there is no `cu_api_version` option. `docintel_api_version=None` delegates to the installed Azure SDK default. See `cloud_and_ocr.md` for the tested SDK versions and network contracts.

Constructor

MarkItDown(
    *,
    enable_builtins: bool | None = None,
    enable_plugins: bool | None = None,
    **kwargs,
)

Built-in converters are enabled by default. Third-party plugins are disabled by default.

Recognized constructor keywords include:

KeywordPurpose
requests_sessionCustom requests.Session used by HTTP(S) URI conversion
llm_clientOpenAI-compatible client for image descriptions and compatible plugins
llm_modelProvider-specific model identifier
llm_promptPrompt for image description/OCR
exiftool_pathExplicit trusted ExifTool executable
style_mapMammoth style map for DOCX conversion
docintel_endpointEnable Azure Document Intelligence
docintel_credentialExplicit AzureKeyCredential or token credential
docintel_file_typesRestrict Document Intelligence routing
docintel_api_versionAzure Document Intelligence API version
cu_endpointEnable Azure Content Understanding
cu_credentialExplicit AzureKeyCredential or token credential
cu_analyzer_idCustom Content Understanding analyzer
cu_file_typesRestrict Content Understanding routing

The public signature uses **kwargs; spell these names exactly. Unknown names can be silently ignored: there is no cu_api_version option. docintel_api_version=None delegates to the installed Azure SDK default. See cloud_and_ocr.md for the tested SDK versions and network contracts.

Raw lines 32 to 65
66### Conversion methods
68#### `convert()`
70```python
71convert(
72 source: str | Path | requests.Response | BinaryIO,
73 *,
74 stream_info: StreamInfo | None = None,
75 **kwargs,
76) -> DocumentConverterResult
77```
79Dispatch rules:
81- `str` with a parsed `http:`, `https:`, `file:`, or `data:` scheme (case-insensitive) → `convert_uri()`
82- other `str` or `Path` → `convert_local()`
83- `requests.Response` → `convert_response()`
84- binary file-like object → `convert_stream()`
85- text stream → `TypeError`
87This convenience method is broad. Prefer a narrower method for untrusted or application-facing inputs.
89#### `convert_local()`
91```python
92convert_local(
93 path: str | Path,
94 *,
95 stream_info: StreamInfo | None = None,
96 file_extension: str | None = None,
97 url: str | None = None,
98 **kwargs,
99) -> DocumentConverterResult
100```
102`file_extension` and `url` are legacy parameters; put overrides in `StreamInfo`.
104```python
105from pathlib import Path
107from markitdown import MarkItDown
109source = Path("experiment.xlsx")
110result = MarkItDown().convert_local(source)
111Path("experiment.md").write_text(result.markdown, encoding="utf-8")
112```
114#### `convert_stream()`
116```python
117convert_stream(
118 stream: BinaryIO,
119 *,
120 stream_info: StreamInfo | None = None,
121 file_extension: str | None = None,
122 url: str | None = None,
123 **kwargs,
124) -> DocumentConverterResult
125```
127Requirements and behavior:
129- The stream must be binary.
130- A seekable stream is preferred.
131- A non-seekable stream is copied completely into an in-memory `BytesIO`.
132- `file_extension` and `url` are legacy hints; prefer `StreamInfo`.
134```python
135from io import BytesIO
137from markitdown import MarkItDown, StreamInfo
139payload = b"sample,value\ncontrol,1\ntreated,2\n"
140result = MarkItDown().convert_stream(
141 BytesIO(payload),
142 stream_info=StreamInfo(
143 extension=".csv",
144 mimetype="text/csv",
145 charset="utf-8",
146 filename="results.csv",
147 ),
149print(result.markdown)
150```
152#### `convert_uri()`
154```python
155convert_uri(
156 uri: str,
157 *,
158 stream_info: StreamInfo | None = None,
159 file_extension: str | None = None,
160 mock_url: str | None = None,
161 **kwargs,
162) -> DocumentConverterResult
163```
165Supported schemes:
167- `file:` with an empty authority or `localhost`
168- `data:`
169- `http:`
170- `https:`
172HTTP(S) conversion uses the configured `requests.Session`, follows Requests defaults, and then buffers the complete response in memory. It does not provide an application-level SSRF policy, download-size limit, or redirect allowlist. Validate and fetch remote resources yourself before calling `convert_response()`.
174`convert_url()` remains a backward-compatible alias, but new code should use `convert_uri()`.
176#### `convert_response()`
178```python
179convert_response(
180 response: requests.Response,
181 *,
182 stream_info: StreamInfo | None = None,
183 file_extension: str | None = None,
184 url: str | None = None,
185 **kwargs,
186) -> DocumentConverterResult
187```
189The method derives hints from `Content-Type`, `Content-Disposition`, and the response URL, then buffers every response chunk into memory. The caller is responsible for destination validation, redirect handling, timeout, maximum size, authentication, and TLS policy.

Conversion methods

convert()

convert(
    source: str | Path | requests.Response | BinaryIO,
    *,
    stream_info: StreamInfo | None = None,
    **kwargs,
) -> DocumentConverterResult

Dispatch rules:

  • str with a parsed http:, https:, file:, or data: scheme (case-insensitive) → convert_uri()
  • other str or Path → convert_local()
  • requests.Response → convert_response()
  • binary file-like object → convert_stream()
  • text stream → TypeError

This convenience method is broad. Prefer a narrower method for untrusted or application-facing inputs.

convert_local()

convert_local(
    path: str | Path,
    *,
    stream_info: StreamInfo | None = None,
    file_extension: str | None = None,
    url: str | None = None,
    **kwargs,
) -> DocumentConverterResult

file_extension and url are legacy parameters; put overrides in StreamInfo.

from pathlib import Path

from markitdown import MarkItDown

source = Path("experiment.xlsx")
result = MarkItDown().convert_local(source)
Path("experiment.md").write_text(result.markdown, encoding="utf-8")

convert_stream()

convert_stream(
    stream: BinaryIO,
    *,
    stream_info: StreamInfo | None = None,
    file_extension: str | None = None,
    url: str | None = None,
    **kwargs,
) -> DocumentConverterResult

Requirements and behavior:

  • The stream must be binary.
  • A seekable stream is preferred.
  • A non-seekable stream is copied completely into an in-memory BytesIO.
  • file_extension and url are legacy hints; prefer StreamInfo.
from io import BytesIO

from markitdown import MarkItDown, StreamInfo

payload = b"sample,value\ncontrol,1\ntreated,2\n"
result = MarkItDown().convert_stream(
    BytesIO(payload),
    stream_info=StreamInfo(
        extension=".csv",
        mimetype="text/csv",
        charset="utf-8",
        filename="results.csv",
    ),
)
print(result.markdown)

convert_uri()

convert_uri(
    uri: str,
    *,
    stream_info: StreamInfo | None = None,
    file_extension: str | None = None,
    mock_url: str | None = None,
    **kwargs,
) -> DocumentConverterResult

Supported schemes:

  • file: with an empty authority or localhost
  • data:
  • http:
  • https:

HTTP(S) conversion uses the configured requests.Session, follows Requests defaults, and then buffers the complete response in memory. It does not provide an application-level SSRF policy, download-size limit, or redirect allowlist. Validate and fetch remote resources yourself before calling convert_response().

convert_url() remains a backward-compatible alias, but new code should use convert_uri().

convert_response()

convert_response(
    response: requests.Response,
    *,
    stream_info: StreamInfo | None = None,
    file_extension: str | None = None,
    url: str | None = None,
    **kwargs,
) -> DocumentConverterResult

The method derives hints from Content-Type, Content-Disposition, and the response URL, then buffers every response chunk into memory. The caller is responsible for destination validation, redirect handling, timeout, maximum size, authentication, and TLS policy.

Raw lines 66 to 190
Starts an agent Dispatch :79
191## `StreamInfo`
193```python
194StreamInfo(
195 *,
196 mimetype: str | None = None,
197 extension: str | None = None,
198 charset: str | None = None,
199 filename: str | None = None,
200 local_path: str | None = None,
201 url: str | None = None,
203```
205Examples:
207```python
208pdf_info = StreamInfo(
209 mimetype="application/pdf",
210 extension=".pdf",
211 filename="paper.pdf",
214html_info = StreamInfo(
215 mimetype="text/html",
216 extension=".html",
217 charset="utf-8",
218 filename="article.html",
220```
222Hints are merged with extension, HTTP header, and Magika content-detection guesses. If a caller-supplied hint conflicts with content detection, MarkItDown may try both guesses.

StreamInfo

StreamInfo(
    *,
    mimetype: str | None = None,
    extension: str | None = None,
    charset: str | None = None,
    filename: str | None = None,
    local_path: str | None = None,
    url: str | None = None,
)

Examples:

pdf_info = StreamInfo(
    mimetype="application/pdf",
    extension=".pdf",
    filename="paper.pdf",
)

html_info = StreamInfo(
    mimetype="text/html",
    extension=".html",
    charset="utf-8",
    filename="article.html",
)

Hints are merged with extension, HTTP header, and Magika content-detection guesses. If a caller-supplied hint conflicts with content detection, MarkItDown may try both guesses.

Raw lines 191 to 223
224## `DocumentConverterResult`
226```python
227DocumentConverterResult(
228 markdown: str,
229 *,
230 title: str | None = None,
232```
234Attributes and conversions:
236| Interface | Status |
237|---|---|
238| `result.markdown` | Canonical converted Markdown |
239| `result.title` | Optional source-derived title |
240| `result.text_content` | Soft-deprecated alias for `markdown` |
241| `str(result)` | Returns `markdown` |
243```python
244result = MarkItDown().convert_local("paper.pdf")
245markdown = result.markdown
246title = result.title
247```

DocumentConverterResult

DocumentConverterResult(
    markdown: str,
    *,
    title: str | None = None,
)

Attributes and conversions:

InterfaceStatus
result.markdownCanonical converted Markdown
result.titleOptional source-derived title
result.text_contentSoft-deprecated alias for markdown
str(result)Returns markdown
result = MarkItDown().convert_local("paper.pdf")
markdown = result.markdown
title = result.title
Raw lines 224 to 248
249## Per-conversion Options
251Converter-specific values can be forwarded through a conversion call:
253```python
254result = converter.convert_local(
255 "page.html",
256 keep_data_uris=False,
258```
260Common options:
262| Option | Used by |
263|---|---|
264| `keep_data_uris` | HTML/Markdown conversion; preserve rather than truncate data URIs |
265| `youtube_transcript_languages` | YouTube transcript language preference |
266| `llm_client`, `llm_model`, `llm_prompt` | Image/PPTX description and compatible plugins |
267| `style_map` | DOCX conversion |
268| `exiftool_path` | Image/audio metadata |

Per-conversion Options

Converter-specific values can be forwarded through a conversion call:

result = converter.convert_local(
    "page.html",
    keep_data_uris=False,
)

Common options:

OptionUsed by
keep_data_urisHTML/Markdown conversion; preserve rather than truncate data URIs
youtube_transcript_languagesYouTube transcript language preference
llm_client, llm_model, llm_promptImage/PPTX description and compatible plugins
style_mapDOCX conversion
exiftool_pathImage/audio metadata
Raw lines 249 to 269
270## Exceptions
272```python
273from markitdown import (
274 FileConversionException,
275 MissingDependencyException,
276 UnsupportedFormatException,
278```
280| Exception | Meaning |
281|---|---|
282| `MissingDependencyException` | The converter matched, but its optional dependency is unavailable |
283| `UnsupportedFormatException` | No registered converter accepted the source |
284| `FileConversionException` | One or more matching converters attempted and failed |
285| `TypeError` | `convert()` received an unsupported source type, such as a text stream |
287```python
288from markitdown import (
289 FileConversionException,
290 MarkItDown,
291 MissingDependencyException,
292 UnsupportedFormatException,
295try:
296 result = MarkItDown().convert_local("input.pdf")
297except MissingDependencyException:
298 print("Install markitdown[pdf]==0.1.8")
299except UnsupportedFormatException:
300 print("No converter accepted this input")
301except FileConversionException as exc:
302 print(f"A matching converter failed: {exc}")
303```

Exceptions

from markitdown import (
    FileConversionException,
    MissingDependencyException,
    UnsupportedFormatException,
)
ExceptionMeaning
MissingDependencyExceptionThe converter matched, but its optional dependency is unavailable
UnsupportedFormatExceptionNo registered converter accepted the source
FileConversionExceptionOne or more matching converters attempted and failed
TypeErrorconvert() received an unsupported source type, such as a text stream
from markitdown import (
    FileConversionException,
    MarkItDown,
    MissingDependencyException,
    UnsupportedFormatException,
)

try:
    result = MarkItDown().convert_local("input.pdf")
except MissingDependencyException:
    print("Install markitdown[pdf]==0.1.8")
except UnsupportedFormatException:
    print("No converter accepted this input")
except FileConversionException as exc:
    print(f"A matching converter failed: {exc}")
Raw lines 270 to 304
305## Converter Registration
307```python
308register_converter(
309 converter: DocumentConverter,
310 *,
311 priority: float = PRIORITY_SPECIFIC_FILE_FORMAT,
312) -> None
313```
315Lower numeric priorities run first. The built-in specific-format priority is `0.0`; generic converters use `10.0`. For registrations with equal priority, the most recently registered converter is attempted first.
317`register_page_converter()` is deprecated.

Converter Registration

register_converter(
    converter: DocumentConverter,
    *,
    priority: float = PRIORITY_SPECIFIC_FILE_FORMAT,
) -> None

Lower numeric priorities run first. The built-in specific-format priority is 0.0; generic converters use 10.0. For registrations with equal priority, the most recently registered converter is attempted first.

register_page_converter() is deprecated.

Raw lines 305 to 318
319## Custom Converter
321Version 0.1.x converters operate on binary streams and implement both `accepts()` and `convert()`:
323```python
324from typing import Any, BinaryIO
326from markitdown import (
327 DocumentConverter,
328 DocumentConverterResult,
329 StreamInfo,
333class RtfConverter(DocumentConverter):
334 def accepts(
335 self,
336 file_stream: BinaryIO,
337 stream_info: StreamInfo,
338 **kwargs: Any,
339 ) -> bool:
340 return (stream_info.extension or "").lower() == ".rtf"
342 def convert(
343 self,
344 file_stream: BinaryIO,
345 stream_info: StreamInfo,
346 **kwargs: Any,
347 ) -> DocumentConverterResult:
348 raw = file_stream.read()
349 # Replace this placeholder with a real, bounded RTF parser.
350 return DocumentConverterResult(
351 markdown=f"```text\n{raw.decode('utf-8', errors='replace')}\n```"
352 )
353```
355Do not advance the stream in `accepts()`. If inspection is necessary, save the position with `tell()` and restore it with `seek()`.

Custom Converter

Version 0.1.x converters operate on binary streams and implement both accepts() and convert():

from typing import Any, BinaryIO

from markitdown import (
    DocumentConverter,
    DocumentConverterResult,
    StreamInfo,
)


class RtfConverter(DocumentConverter):
    def accepts(
        self,
        file_stream: BinaryIO,
        stream_info: StreamInfo,
        **kwargs: Any,
    ) -> bool:
        return (stream_info.extension or "").lower() == ".rtf"

    def convert(
        self,
        file_stream: BinaryIO,
        stream_info: StreamInfo,
        **kwargs: Any,
    ) -> DocumentConverterResult:
        raw = file_stream.read()
        # Replace this placeholder with a real, bounded RTF parser.
        return DocumentConverterResult(
            markdown=f"```text\n{raw.decode('utf-8', errors='replace')}\n```"
        )

Do not advance the stream in accepts(). If inspection is necessary, save the position with tell() and restore it with seek().

Raw lines 319 to 356
357## Plugin Package Contract
359The plugin module exports interface version 1 and a registration function:
361```python
362from markitdown import MarkItDown
364__plugin_interface_version__ = 1
367def register_converters(markitdown: MarkItDown, **kwargs) -> None:
368 markitdown.register_converter(RtfConverter())
369```
371Register the module through `pyproject.toml`:
373```toml
374[project.entry-points."markitdown.plugin"]
375example = "example_markitdown_plugin"
376```
378Inspect and install a trusted, pinned plugin, then verify discovery:
380```bash
381markitdown --list-plugins
382markitdown --use-plugins input.rtf -o output.md
383```

Plugin Package Contract

The plugin module exports interface version 1 and a registration function:

from markitdown import MarkItDown

__plugin_interface_version__ = 1


def register_converters(markitdown: MarkItDown, **kwargs) -> None:
    markitdown.register_converter(RtfConverter())

Register the module through pyproject.toml:

[project.entry-points."markitdown.plugin"]
example = "example_markitdown_plugin"

Inspect and install a trusted, pinned plugin, then verify discovery:

markitdown --list-plugins
markitdown --use-plugins input.rtf -o output.md
Raw lines 357 to 384
385## CLI Reference
387```text
388markitdown [options] [filename]
389```
391If `filename` is omitted, MarkItDown buffers all binary stdin in memory before detection. Document Intelligence mode requires a filename; CU accepts hinted stdin.
393| Option | Meaning |
394|---|---|
395| `-v`, `--version` | Print package version |
396| `-o`, `--output PATH` | Write UTF-8 Markdown to a file |
397| `-x`, `--extension EXT` | File-extension hint |
398| `-m`, `--mime-type TYPE` | MIME-type hint |
399| `-c`, `--charset NAME` | Charset hint |
400| `-d`, `--use-docintel` | Use Azure Document Intelligence |
401| `-e`, `--endpoint URL` | Document Intelligence endpoint; fallback `MARKITDOWN_DOCINTEL_ENDPOINT` |
402| `--use-cu`, `--use-content-understanding` | Use Azure Content Understanding |
403| `--cu-endpoint URL` | Content Understanding endpoint; fallback `MARKITDOWN_CU_ENDPOINT` |
404| `--cu-analyzer ID` | Custom analyzer ID |
405| `--cu-file-types LIST` | Comma-separated CU file types |
406| `-p`, `--use-plugins` | Enable installed third-party plugins |
407| `--list-plugins` | List discovered plugins and exit |
408| `--keep-data-uris` | Preserve full data URIs |
410Document Intelligence and Content Understanding are mutually exclusive in one CLI invocation.
412The core 0.1.8 parser does **not** expose `--llm-client` or `--llm-model`. Configure image descriptions or the OCR plugin through Python.

CLI Reference

markitdown [options] [filename]

If filename is omitted, MarkItDown buffers all binary stdin in memory before detection. Document Intelligence mode requires a filename; CU accepts hinted stdin.

OptionMeaning
-v, --versionPrint package version
-o, --output PATHWrite UTF-8 Markdown to a file
-x, --extension EXTFile-extension hint
-m, --mime-type TYPEMIME-type hint
-c, --charset NAMECharset hint
-d, --use-docintelUse Azure Document Intelligence
-e, --endpoint URLDocument Intelligence endpoint; fallback MARKITDOWN_DOCINTEL_ENDPOINT
--use-cu, --use-content-understandingUse Azure Content Understanding
--cu-endpoint URLContent Understanding endpoint; fallback MARKITDOWN_CU_ENDPOINT
--cu-analyzer IDCustom analyzer ID
--cu-file-types LISTComma-separated CU file types
-p, --use-pluginsEnable installed third-party plugins
--list-pluginsList discovered plugins and exit
--keep-data-urisPreserve full data URIs

Document Intelligence and Content Understanding are mutually exclusive in one CLI invocation.

The core 0.1.8 parser does not expose --llm-client or --llm-model. Configure image descriptions or the OCR plugin through Python.

Raw lines 385 to 413
414## Source Basis
416- v0.1.8 package API: https://github.com/microsoft/markitdown/tree/v0.1.8/packages/markitdown/src/markitdown
417- v0.1.8 CLI: https://github.com/microsoft/markitdown/blob/v0.1.8/packages/markitdown/src/markitdown/__main__.py
418- v0.1.8 sample plugin: https://github.com/microsoft/markitdown/tree/v0.1.8/packages/markitdown-sample-plugin

Source Basis

  • v0.1.8 package API: https://github.com/microsoft/markitdown/tree/v0.1.8/packages/markitdown/src/markitdown
  • v0.1.8 CLI: https://github.com/microsoft/markitdown/blob/v0.1.8/packages/markitdown/src/markitdown/__main__.py
  • v0.1.8 sample plugin: https://github.com/microsoft/markitdown/tree/v0.1.8/packages/markitdown-sample-plugin
Raw lines 414 to 418