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")
Why Rosettes?
O(n) Guaranteed
Every lexer processes input in linear time. No regex patterns that can be exploited for denial-of-service attacks.
55 Languages
Hand-written state machines for Python, JavaScript, Rust, Go, and 51 more languages. Full syntax support, not just keywords.
Free-Threading Ready
Optimized for Python 3.14t (PEP 703). True parallelism withhighlight_many()for multi-core systems.
Pygments Compatible
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
Benchmarked against Pygments (source):
| File Size | Rosettes | Pygments | Speedup |
|---|---|---|---|
| ~50 lines | 0.5ms | 1.5ms | 2.8x |
| ~500 lines | 5ms | 15ms | 3.2x |
| 10,000 lines | 220ms | 860ms | 3.9x |