Examples

Runnable examples showcasing Patitas capabilities

1 min read 193 words

Runnable examples are in theexamples/directory of the Patitas repo. Run from repo root:

python examples/basic/hello_markdown.py

Or with uv run:

uv run python examples/basic/hello_markdown.py

Example Index

Example What it shows
basic/hello_markdown.py Parse + render in 3 lines
basic/markdown_class.py High-level API (mistune-like)
notebooks/parse_notebook.py Jupyter .ipynb parsing, zero deps
ast/typed_ast_walk.py Visitor: collect headings for TOC
ast/transform_headings.py Immutable AST transform
directives/builtin_directives.py Admonition, dropdown, tabs
directives/custom_directive.py Add your own directive
incremental/edit_simulation.py O(change) re-parse
differ/ast_diff.py Structural diff between parses
plugins/math_and_tables.py Tables, math, footnotes
advanced/parallel_parse.py Free-threading safe parallel parse
advanced/serialize_ast.py JSON round-trip for caching
llm_safety/llm_safe_context.py Sanitize + render markdown for LLM context

Requirements

  • pip install patitas (or uv syncin repo)
  • Optional:pip install patitas[syntax]for syntax highlighting in code blocks

See Also

  • LLM Safety — Full guide for the parse → sanitize → render_llm pipeline
  • API Reference — Complete API documentation