Patitas

A Python Markdown parser and CommonMark parser for typed ASTs, directives, frontmatter, and notebook content

Python Markdown Parser for Modern Content

CommonMark. Typed AST. Secure parsing.

Patitas is a pure-Python Markdown parser for HTML rendering, content pipelines, and Markdown tooling. It uses a state-machine lexer with O(n) guaranteed parsing, exposes a typed AST, and supports directives, frontmatter, notebook parsing, and LLM-safe output.

from patitas import Markdown

md = Markdown()
html = md("# Hello **World**")
# Output: <h1>Hello <strong>World</strong></h1>

Why Use Patitas

State-Machine Lexer

No regex catastrophic backtracking. O(n) guaranteed parsing with predictable performance on any input.

Free-Threading Ready

Built for Python 3.14t (PEP 703). Parse documents concurrently without the GIL.

CommonMark Compliant

Passes all 652 CommonMark 0.31.2 specification tests. Standards-first design.

Zero Dependencies

Pure Python with no runtime dependencies. Optional extras for directives and syntax highlighting.

Common Use Cases

  • Parsing Markdown to HTML in Python applications
  • Extracting typed structure from Markdown for analysis or transforms
  • Handling YAML frontmatter and notebook content in publishing pipelines
  • Replacing regex-heavy Markdown parsers in security-sensitive systems
  • Powering docs stacks with directives, syntax highlighting, and incremental parsing

Performance

  • 652 CommonMark examples — low tens of milliseconds in recent Python 3.14 local runs
  • Incremental parsing — For small edits in large documents,parse_incrementalcan be much faster than full re-parse
  • Parallel scaling — Free-threaded speedups vary by Python build, hardware, and corpus

Patitas prioritizes safety over raw speed: O(n) guaranteed parsing, typed AST, and full thread-safety.


Typed AST

Every node is a frozen dataclass with full type information:

from patitas import parse

doc = parse("# Hello **World**")
heading = doc[0]

# Type-safe access
print(heading.level)      # 1
print(heading.children)   # [Text, Strong]

# IDE autocompletion works
heading.level  # int
heading.children[1].children  # Sequence[Inline]

The Bengal Ecosystem

A structured reactive stack — every layer written in pure Python for 3.14t free-threading.

ᓚᘏᗢ Bengal Static site generator Docs
∿∿ Purr Content runtime
⌁⌁ Chirp Web framework Docs
=^..^= Pounce ASGI server Docs
)彡 Kida Template engine Docs
ฅᨐฅ Patitas Markdown parser ← You are here Docs
⌾⌾⌾ Rosettes Syntax highlighter Docs

Python-native. Free-threading ready. No npm required.