markdown-it-accel
Rust-accelerated backend for markdown-it-py
markdown-it-accel provides a drop-in Rust-accelerated backend for markdown-it-py, offering significant performance improvements for markdown rendering while maintaining full compatibility with the original Python implementation.
Features
- Blazing fast performance: Up to 80x speedup on typical documents, 200x+ on large documents
- Drop-in acceleration: Simply import and apply to existing markdown-it-py instances
- Automatic fallback: Gracefully falls back to Python implementation when needed
- Full CommonMark support: Powered by pulldown-cmark
- Cross-platform: Pre-built wheels for Linux, macOS, and Windows
- Python 3.8+ support: Compatible with modern Python versions
Installation
Install from PyPI:
pip install markdown-it-accel
For development or building from source:
# Clone the repository
git clone https://github.com/ChungNYCU/markdown-it-accel.git
cd markdown-it-accel
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install in development mode
pip install maturin
maturin develop
Quick Start
from markdown_it import MarkdownIt
from markdown_it_accel import use_rust_core
# Create a markdown-it-py instance
md = MarkdownIt()
# Apply Rust acceleration
use_rust_core(md)
# Use as normal - now with Rust speed!
html = md.render("# Hello, *World*!")
print(html) # <h1>Hello, <em>World</em>!</h1>
Performance
Based on comprehensive benchmarking, markdown-it-accel delivers significant performance improvements:
Performance Results
Overall Speedup: 67x faster on average
| Document Type | Size | Python Time | Rust Time | Speedup |
|---|---|---|---|---|
| BIG.md | 8.0KB | 5.69ms | 71.3μs | 79.88x |
| CODE_HEAVY.md | 8.7KB | 1.28ms | 27.6μs | 46.56x |
| HUGE.md | 434KB | 230.80ms | 3.57ms | 64.68x |
| TABLE_HEAVY.md | 2.1KB | 3.55ms | 46.5μs | 76.36x |
Library Comparison
Compared to other Python markdown libraries:
| Library | Time | Throughput | Relative Performance |
|---|---|---|---|
| markdown-it-accel (Rust) | 80.1μs | 100.5M chars/sec | Fastest |
| markdown-it-py (Python) | 5.72ms | 1.4M chars/sec | 71x slower |
| python-markdown | 25.00ms | 322K chars/sec | 312x slower |
Scaling Performance
Performance scales excellently with document size:
- 1x size: 38x speedup
- 10x size: 132x speedup
- 50x size: 201x speedup
Run benchmarks on your system:
# Comprehensive benchmark suite
python bench/scripts/benchmark.py
# Library comparison
python bench/scripts/compare_libraries.py
Configuration
Environment Variables
MARKDOWN_IT_ACCEL=0: Disable Rust acceleration (fallback to Python)MARKDOWN_IT_ACCEL=1: Enable Rust acceleration (default)
# Disable Rust acceleration
MARKDOWN_IT_ACCEL=0 python your_script.py
# Enable Rust acceleration (default behavior)
MARKDOWN_IT_ACCEL=1 python your_script.py
Checking Availability
from markdown_it_accel import is_available, get_version
print(f"Rust acceleration available: {is_available()}")
print(get_version())
Compatibility
Supported Features
- Headers (
#,##, etc.) - Emphasis (
*italic*,**bold**) - Links (
[text](url)) - Images (
) - Lists (ordered and unordered)
- Code blocks (fenced and indented)
- Blockquotes (
>) - Tables (GFM extension)
- Strikethrough (
~~text~~) - Line breaks and paragraphs
Fallback Behavior
The library automatically falls back to the Python implementation when:
- Rust extension is not available (installation without binary wheels)
- Unsupported syntax is detected
- Rust renderer encounters an error
This ensures your code continues to work regardless of the environment.
Limitations
Currently, some advanced markdown-it-py features may trigger fallback:
- Custom plugins and renderers
- Complex HTML blocks
- Math expressions (
$$...$$) - Mermaid diagrams
Development
Prerequisites
- Python 3.8+
- Rust 1.70+
- maturin
Setup
# Clone and enter directory
git clone https://github.com/ChungNYCU/markdown-it-accel.git
cd markdown-it-accel
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # or .venv\Scripts\activate on Windows
# Install dependencies
pip install -e .[dev]
Building
# Development build
maturin develop
# Release build
maturin develop --release
# Build wheels
maturin build --release
Testing
# Run tests
pytest tests/
# Run tests with coverage
pytest tests/ --cov=markdown_it_accel
# Run benchmarks
python bench/bench_render.py
Code Quality
# Format Python code
black .
# Lint Python code
ruff check .
# Format Rust code
cargo fmt
# Lint Rust code
cargo clippy
Architecture
The library consists of three main components:
- Rust Core (
src/lib.rs): PyO3 module using pulldown-cmark for fast HTML generation - Python Shim (
markdown_it_accel/_shim.py): Monkey-patches markdown-it-py instances - Fallback Logic: Automatic detection and graceful degradation
How It Works
# Before acceleration
md = MarkdownIt()
html = md.render(text) # Pure Python
# After acceleration
use_rust_core(md)
html = md.render(text) # Rust + Python fallback
The use_rust_core() function replaces the render method with a wrapper that:
- Checks if content is supported by Rust implementation
- Attempts fast Rust rendering via
pulldown-cmark - Falls back to original Python implementation on any issue
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure tests pass (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- markdown-it-py - The Python markdown parser this library accelerates
- pulldown-cmark - The fast Rust markdown parser powering the acceleration
- PyO3 - Rust bindings for Python
- maturin - Build system for Rust-based Python extensions
Changelog
0.1.0 (2025-09-03)
- Initial release
- Basic CommonMark support with Rust acceleration
- Automatic fallback mechanism
- Cross-platform binary wheels
- Comprehensive test suite and benchmarks
Metadata
Release files for markdown-it-accel 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| markdown_it_accel-0.1.0.tar.gz | 74.9 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| markdown_it_accel-0.1.0-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details |
| markdown_it_accel-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
| markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl | CPython 3.8 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 1.2 MB
Release files / markdown_it_accel-0.1.0.tar.gz
| Download URL | markdown_it_accel-0.1.0.tar.gz |
|---|---|
| Size | 74.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a04e77109b87ea764767e3e31312827950e36ce49dda9292a32efb7a33a808b
|
|
BLAKE2b-256 checksum How to use checksums |
9f62a047e4799f54494f73823d6a7a934259fbb6d322f677036771d9c1b44193
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / markdown_it_accel-0.1.0-cp38-abi3-win_amd64.whl
| Download URL | markdown_it_accel-0.1.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 200.0 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
eb9ad2203b93711b717f840456603ec426b35ca766445a6ea638f887e044be6b
|
|
BLAKE2b-256 checksum How to use checksums |
4710a7bc644a03c368d684b7565b5b4235b38d180fd1a4d318491cb1476609a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / markdown_it_accel-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | markdown_it_accel-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 344.5 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f061c9d612d6f046e4baec8ef3c213b8c1ea623fb693e7850eabe215a5732c5a
|
|
BLAKE2b-256 checksum How to use checksums |
a6d0422921886dd827fa862bd22f2b4abae9136e08f8f5497e86ebf233713708
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2025.
Transparency logRelease files / markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | markdown_it_accel-0.1.0-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 286.3 kB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dae0de2ed035660d21342a410df36549a4df01abdf80428a3be73b51bcffa499
|
|
BLAKE2b-256 checksum How to use checksums |
bd828eebed8fc2331696197e738f76021cf1980ce396ab88cbe7898ed32aa987
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2025.
Transparency logRelease files / markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | markdown_it_accel-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 308.1 kB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
dfb17ca29e1694c29bba305cb16bb2e82441e1d69cd5ef3a11b539676fe4b0ba
|
|
BLAKE2b-256 checksum How to use checksums |
2a85058a0c40c82337407d9f4cd6963f8c81b4351838825063898f40d83262a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2025.
Transparency log