Python library¶
The library is the product: the CLI, the API workers, and the MCP server all call it, so there is exactly one
conversion path. import ezmd is light; engines load on first use.
Install with pip install ezmd, or from
a source checkout run your code with uv run python ... (see Install).
Convert¶
import ezmd
result = ezmd.convert(
"fixtures/office/docx-review/input.docx",
profile="compact",
on_progress=lambda p: print(p.stage, p.progress),
)
print(result.markdown) # frontmatter plus body
for w in result.warnings:
print(w.severity, w.kind, w.message)
source may be a path (str or Path), an http(s) URL (fetched through the SSRF guard), bytes, a
binary file object, or an ezmd.inputs.InputRef. For bytes and file objects, pass filename= so
detection has a name to go on; mime= overrides detection.
The result¶
ezmd.Result keeps the intermediate representation, so other profiles and formats render without
converting again.
| Member | What it is |
|---|---|
markdown, body, frontmatter |
The rendered output (frontmatter plus body), the body alone, and the frontmatter as a dict |
sidecar |
The JSON sidecar as a dict, or None for profiles without one (compact) |
warnings |
A list of ezmd.ir.Warning (kind, severity, message, page, block_id, count, detail) |
ok |
False when any warning has severity error (the output may still be usable) |
tokens, truncated |
Token count and whether a token budget cut the output |
render(profile, format, **overrides) |
Render another profile (full, compact, rag, agent) or format (md, json, txt). Returns an ezmd.render.RenderedOutput (not a Result): markdown, body, frontmatter, sidecar, chunks, tokens, truncated, warnings, injection_risk, attachments |
chunks(chunk_tokens=400, overlap=0) |
RAG chunks (ezmd.render.Chunk: id, text, breadcrumb, tokens, pages, block_ids) |
save(path, sidecar=True) |
Write the Markdown to a file, or <stem>.md into an existing directory, plus <stem>.ezmd.json when the profile has a sidecar; image links are rebased so they resolve from the written file |
relocate_images(base) |
A new Result whose image links are relative to the directory base (see Images) |
document |
The IR Document (see Output format) |
rag = result.render("rag") # ezmd.render.RenderedOutput
print(rag.tokens, rag.markdown[:200])
for chunk in result.chunks(chunk_tokens=300):
print(chunk.id, chunk.tokens, chunk.breadcrumb)
result.save("out/report.md") # or an existing directory: writes <stem>.md there
Options¶
ezmd.Options (or a plain dict) mirrors the options object of POST /v1/convert:
opts = ezmd.Options(max_pages=50, comments=False, render={"chunks.chunk_tokens": 600})
result = ezmd.convert("report.pdf", profile="rag", options=opts)
| Field | Default | Meaning |
|---|---|---|
max_pages |
500 | Page cap for paged formats |
max_seconds |
600 | Conversion deadline |
max_bytes |
100 MiB | Input size cap |
tracked_changes, comments, formulas, extract_images |
True |
What document converters keep |
image_dir |
None |
Directory to extract images into (see Images); None writes nothing |
experimental |
True |
Allow experimental converters |
converter |
None |
Force a converter id, e.g. documents.docling_pdf |
allow_private_networks |
False |
Let URL fetches reach private and loopback addresses |
languages |
[] |
Language hints |
extra |
{} |
Converter options with dotted keys, e.g. {"pdf.engine": "pdfium"} |
render |
{} |
Profile overrides with dotted keys, e.g. {"chunks.chunk_tokens": 512} |
Media options (ocr, asr_model, diarize, max_duration_seconds) are accepted now and take effect
when the media converters land (Phase 2).
Images¶
Without image_dir, an embedded picture renders as a link to its path inside the source
(), which says where the bytes live but resolves to nothing on disk. With
image_dir set, the DOCX, PPTX, EPUB, notebook and email converters write each picture to
<image_dir>/images/<name> and the link becomes images/<name>, relative to image_dir:
result = ezmd.convert("deck.pptx", options=ezmd.Options(image_dir="out"))
result.save("out/deck.md") # the links read images/<name> and resolve beside the file
save() rebases the links to wherever the Markdown is written, so result.save("docs/deck.md") with
image_dir="out" writes links of the form ../out/images/<name>. relocate_images(base) does the same
without writing, for code that renders the Markdown itself. Links that point outside image_dir (URLs,
data: images, pictures of formats that do not extract yet) are left alone. PDF pages, images and other
formats that do not emit pictures yet keep the behaviour described on their converter pages.
Many inputs, async¶
for r in ezmd.convert_many(["a.pdf", "b.docx"], workers=4, return_exceptions=True, profile="compact"):
print(r if isinstance(r, Exception) else r.frontmatter["title"])
result = await ezmd.convert_async("report.pdf") # runs on a worker thread; never blocks the event loop
Capabilities, plugins, and memory¶
ezmd.capabilities()returns the registered converters (loaded or unavailable with the reason and the extra that would enable them), profiles, and formats; the same data asezmd capabilities.ezmd.register_converter(converter)registers a converter object in-process. Packaged plugins use theezmd.convertersentry point instead; see Writing a converter plugin.ezmd.unload_models()frees cached engine models.
Errors¶
convert raises:
ezmd.registry.ConversionErrorwhen no converter could produce a document (.codeis a stable reason,.user_messageis safe to show);ezmd.inputs.InputTooLargewhen the input exceedsmax_bytes;- a subclass of
ezmd.core.netguard.NetguardErrorfor URLs (catch the base class for all of them):UrlBlockedwhen the SSRF guard refuses the URL (a private or reserved address, a blocked host, orSchemeNotAllowedfor a scheme other than http and https),FetchFailedwhen it cannot be fetched,ResponseTooLargewhen the body is overmax_bytes, andPlatformDisabled/ResidentialOnlyfor sites disabled by policy or reachable only through a residential fetch node; FileNotFoundErrorfor a missing path.
Losses that do not stop the conversion are warnings on the result, never exceptions. The codes are listed in Warning codes.