Syntax Highlighting, Reinvented
O(n) guaranteed. Zero ReDoS. Thread-safe by design.
Rosettes is a pure-Python syntax highlighter built for the free-threaded era. Every lexer is a hand-written state machine—no regex backtracking, no exponential blowup, no security vulnerabilities.
from rosettes import highlight
html = highlight("def hello(): print('world')", "python")
What's good about it
Every lexer processes input in linear time. No regex patterns that can be exploited for denial-of-service attacks.
Hand-written state machines for Python, JavaScript, Rust, Go, and 51 more languages. Full syntax support, not just keywords.
Optimized for Python 3.14t (PEP 703). True parallelism withhighlight_many()for multi-core systems.
Drop-in CSS class compatibility. Use your existing Pygments themes or Rosettes' semantic classes.
Quick Example
from rosettes import highlight, highlight_many
# Single block
html = highlight("const x = 1;", "javascript")
# Parallel processing (optimal for 8+ blocks)
blocks = [
("def foo(): pass", "python"),
("fn main() {}", "rust"),
("let x = 1;", "javascript"),
]
results = highlight_many(blocks) # 1.5-2x speedup on 3.14t
Performance
| File Size | Time |
|---|---|
| ~50 lines | ~0.5ms |
| ~500 lines | ~5ms |
| 10,000 lines | ~220ms |
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 | Docs |
| ⌾⌾⌾ | Rosettes | Syntax highlighter ← You are here | Docs |
Python-native. Free-threading ready. No npm required.