Skip to content
monosansPublic

About

Blazingly fast Markdown parser for Python written in Rust.

Topics

Resources

Stars

44 stars

Watchers

1 watching

Forks

Repository files navigation

pyromark

Downloads

pyromark (stands for Python Rust Optimized Markdown) is a blazingly fast CommonMark-compliant Markdown 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, mistletoe, markdown2 and marko.

html and write_html release the GIL, so threads render in parallel.

See benchmark.

License

MIT

About

Blazingly fast Markdown parser for Python written in Rust.

Topics

Resources

Stars

44 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages