Skip to content

monosans/pyromark

Repository files navigation

pyromark

CI Downloads

pyromark (stands for Python Rust Optimized Markdown) is a blazingly fast CommonMark-compliant Markdown parser for Python.

Uses pulldown-cmark Rust crate under the hood.

Installation

pip install -U pyromark

Documentation

https://pyromark.readthedocs.io

Basic examples

See documentation for more comprehensive examples.

Convert Markdown to HTML

import pyromark

html = pyromark.html("# Hello world")
assert html == "<h1>Hello world</h1>\n"

Iterating over Markdown elements

import pyromark

for event in pyromark.events("# Hello world"):
    # All event types are fully type annotated
    # so you will get static type checking
    # and Tab completions in your IDE!
    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}")

Performance

160x faster than markdown2, 130x faster than Markdown, 119x faster than mistletoe, 103x faster than markdown-it-py, 75x faster than mistune.

If you use threading, the difference with other libraries will be even more enormous, since pyromark releases the GIL.

See benchmark.

License

MIT

About

Blazingly fast Markdown parser for Python written in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 6