mdream (Python)
Python bindings for mdream — a PyO3 wrapper
around the Rust mdream core engine. Converts HTML to GitHub Flavored Markdown
with frontmatter, lists, tables, and code blocks, through one-shot and streaming
APIs. The GIL is released for the whole conversion, so Python code keeps running
while large documents convert.
- Requires CPython 3.10+ (a single
abi3wheel per platform covers every supported CPython) - No runtime Python dependencies
- MIT licensed, matching the workspace
Python bindings for mdream by harlan-zw (MIT). This is an independent packaging of the upstream Rust core as mdream-py.
Install
From PyPI, once the first wheels are published (distribution name mdream-py,
import name mdream):
pip install mdream-py
From source with maturin:
pip install maturin
maturin develop # build and install into the active virtualenv
# or build a wheel:
maturin build --release
Quickstart
import mdream
md = mdream.html_to_markdown("<h1>Hello</h1><p>World</p>")
# "# Hello\n\nWorld"
# Rich result: markdown plus frontmatter, extracted elements, and the
# truncation flag. Pass options as a plain dict (snake_case keys).
result = mdream.convert(
html,
{
"origin": "https://example.com",
"plugins": {"frontmatter": {}},
},
)
result.markdown # str — the Markdown output
result.frontmatter # dict[str, str] | None — extracted <head> metadata
result.extracted # list[ExtractedElement] | None — extraction plugin matches
result.truncated # bool — True if max_node_bytes dropped content
# Plain text output
text = mdream.html_to_text(html)
mdream.__version__ reports the package version (kept in lockstep with the
workspace crate version).
Streaming
MarkdownStream converts HTML incrementally: feed chunks as they arrive and
collect the Markdown as it is produced. Joining the chunk outputs always equals
the one-shot conversion of the same input, even when a chunk boundary splits
HTML mid-tag.
from mdream import MarkdownStream
stream = MarkdownStream()
for chunk in chunks: # e.g. a network response body
md_part = stream.process_chunk(chunk)
write(md_part) # Markdown as it becomes ready
tail = stream.finish() # flush remaining output
write(tail)
stream.truncated # bool — True if max_node_bytes fired
data = stream.take_data() # {"extracted": [...], "frontmatter": {...}}
take_data() returns the elements collected by the extraction plugin and the
frontmatter extracted so far; extracted drains on call and is complete after
finish(). The GIL is released around each chunk's conversion work.
Options
Options are plain dicts with snake_case keys (a deliberate divergence from the
JS engines' camelCase). Every key is validated: an unknown key at any level
raises ValueError naming the key, a bad format or negative wrap_width
raises ValueError, and wrong value types raise TypeError.
Top-level keys (all optional):
| Key | Type | Default | Description |
|---|---|---|---|
origin |
str |
— | Base URL used to resolve relative links and image sources. |
clean |
dict |
— | Post-processing cleanup rules (see below). |
plugins |
dict |
— | Plugin configuration (see below). |
wrap_width |
int |
0 |
Hard-wrap prose at this many characters, breaking on word boundaries. 0 disables wrapping. Code, tables, and headings are never wrapped. |
format |
str |
"markdown" |
Output format: "markdown", "text", or "html". |
max_node_bytes |
int |
0 |
Safety cap in bytes on what one construct may buffer — a text node, a tag, an open code block or inline code span, a table row's columns, or extraction script text. 0 (the default) is unlimited; content past the cap is dropped, bounding memory on adversarial input. Useful when streaming untrusted email. truncated in the result (or MarkdownStream.truncated) reports whether it fired. |
clean
All flags are bool, false by default:
| Key | Description |
|---|---|
urls |
Strip tracking query parameters from URLs (utm_*, fbclid, gclid, …). |
fragments |
Strip fragment-only links that don't match any heading slug. |
empty_links |
Strip links with meaningless or executable hrefs to plain text. |
redundant_links |
Strip links where the text equals the URL: [https://x.com](https://x.com) → https://x.com. |
self_link_headings |
Strip self-referencing heading anchors: ## [Title](#title) → ## Title. |
empty_images |
Strip images with no alt text:  → nothing. |
empty_link_text |
Drop links that produce no visible text: [](url) → nothing. |
plugins
| Key | Type | Description |
|---|---|---|
filter |
dict |
Filter content by CSS selector: include (list of selectors to keep, dropping everything else), exclude (list of selectors to remove), process_children (bool — when true, children of an excluded element are still processed). |
isolate_main |
bool |
Restrict output to the page's <main> element. Pass True to enable. |
frontmatter |
dict |
Extract <head> metadata into YAML frontmatter: additional_fields (dict of {name: value} string pairs appended to the frontmatter; reserved keys such as title are ignored), meta_fields (list of extra <meta name="..."> keys to extract beyond the defaults). |
tailwind |
bool |
Convert Tailwind utility classes to semantic Markdown. Pass True to enable. |
extraction |
dict |
selectors (list of CSS selectors); matched elements are collected into the result's extracted / take_data()["extracted"]. |
tag_overrides |
dict |
Per-tag rendering overrides keyed by lowercase tag name (see below). |
tag_overrides
Each value is a dict with any of:
| Key | Type | Description |
|---|---|---|
enter |
str |
String emitted when entering the tag, replacing its default opening Markdown. |
exit |
str |
String emitted when exiting the tag, replacing its default closing Markdown. |
spacing |
[int, int] |
Blank lines [before, after] around the tag's output. [0, 0] keeps it inline. |
is_inline |
bool |
Treat the tag as inline (true) or block (false). |
is_self_closing |
bool |
Treat the tag as void/self-closing (like <br>). |
collapses_inner_white_space |
bool |
Collapse runs of whitespace inside the tag to a single space. |
alias |
str |
Name of a built-in tag to render exactly like (e.g. "em"). Unknown tag names raise ValueError. |
mdream.html_to_markdown(
html,
{"plugins": {"tag_overrides": {"sup": {"enter": "^", "exit": "^", "is_inline": True}}}},
)
Platform support
Prebuilt abi3 wheels (CPython 3.10+) are published for:
- macOS (arm64)
- Linux (x86_64)
Everything else builds from the sdist with a Rust toolchain and maturin.
Known limitations
- Free-threaded CPython:
abi3wheels are incompatible with free-threaded CPython 3.13t/3.14t. If you need free-threaded Python, a separatecp3xxtwheel would be required; build from the sdist in the meantime. - Panic safety: Rust panics are caught and re-raised as Python
RuntimeError(mdream internal error: ...) rather than crashing the interpreter. That path is implemented but not deterministically triggerable from pure Python, so it is an accepted, documented gap — no test asserts it end-to-end. - No
html2textcompatibility layer: the package ships a clean native API (one-shot + streaming).html2textremains a benchmark baseline only.
API surface
| Symbol | Kind | Description |
|---|---|---|
mdream.html_to_markdown(html, options=None) |
function | One-shot conversion → Markdown str. |
mdream.convert(html, options=None) |
function | One-shot conversion → MdreamResult. |
mdream.html_to_text(html, options=None) |
function | One-shot conversion → plain-text str. |
mdream.MarkdownStream(options=None) |
class | Streaming converter: process_chunk(chunk), finish(), truncated, take_data(). |
mdream.MdreamResult |
type | markdown, extracted, frontmatter, truncated. |
mdream.ExtractedElement |
type | selector, tag_name, text_content, attributes. |
mdream.__version__ |
str |
Package version, in lockstep with the workspace crate. |
The native extension lives in mdream._mdream; the mdream package re-exports
the public API above, ships inline .pyi stubs, and is marked typed
(py.typed).
Metadata
Release files for mdream-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mdream_py-0.1.0.tar.gz | 273.5 kB | With provenance | Details for mdream_py-0.1.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mdream_py-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for mdream_py-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl |
| mdream_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for mdream_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
Total release size: 1.2 MB
Release files / mdream_py-0.1.0.tar.gz
| Download URL | mdream_py-0.1.0.tar.gz |
|---|---|
| Size | 273.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f3d575afd0e18017d700320023e82e0a4f48e21afd605ccd32fba6e16346e21
|
|
BLAKE2b-256 checksum How to use checksums |
2a0a849f8aa097fba4ed64616aecdb8124e4b5eb9e7baad074188c19d2402c1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / mdream_py-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | mdream_py-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 464.4 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
de8cb3f345fa917cc49bfcdf19ecf79d003a55407bbc625e294a7f50fe059c2f
|
|
BLAKE2b-256 checksum How to use checksums |
8f14317827a89a25a3efa118427e5a41cfe6a9b67aef1c444440441df4d3d808
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / mdream_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | mdream_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 433.0 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
61638cee0dbe6c13d54fa0c561cb815db9b6af29c46cf28787ae9289c2fa13f5
|
|
BLAKE2b-256 checksum How to use checksums |
6ee777b531ba37b1498a67ef2b6c833d1760dd61ec650cbb0a3fd37eb3dc4a9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for mdream-py 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 3 files in this release have been uploaded with provenance metadata.
Attestation for mdream_py-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.