Blazingly fast CommonMark-compliant Markdown pull parser for Python, written in Rust
Actively maintained. Last release 2 weeks ago, commits in 26 of the last 26 weeks. A safe choice.
pip install pyromark
pyromark
pyromark (stands for Python Rust Optimized Markdown) is a blazingly fast CommonMark-compliant Markdown pull parser for Python, built on the pulldown-cmark Rust crate.
Installation
uv add pyromark
# or
pip install -U pyromark
Documentation
https://monosans.github.io/pyromark
Examples
Convert Markdown to HTML
import pyromark
html = pyromark.html("# Hello world")
assert html == "<h1>Hello world</h1>\n"
The output is not sanitized, so sanitize it before serving Markdown you did not write.
Iterate over Markdown elements
import pyromark
for event in pyromark.events("# Hello world"):
match event:
case {"Start": {"Heading": {"level": heading_level}}}:
print(f"Heading with {heading_level} level started")
case {"Text": text}:
print(f"Got {text!r} text")
case {"End": {"Heading": heading_level}}:
print(f"Heading with {heading_level} level ended")
case other_event:
print(f"Got {other_event!r}")
Events are fully type annotated, so your editor knows the shape of each one.
Enable extensions and highlight code
import pyromark
html = pyromark.html(
"| a | b |\n| - | - |\n| 1 | 2 |",
options=pyromark.Options.ENABLE_TABLES,
highlight=pyromark.Theme.INSPIRED_GITHUB,
)
Command line
pyromark README.md --enable-tables --highlight inspired-github -o out.html
Performance
2.6x faster than cmarkgfm (C) and comrak (Rust). 86x to 367x faster than pure Python parsers: mistune, markdown-it-py, Markdown, , and .