Released: January 2, 2026
Initial public release of Rosettes, extracted from the Bengal static site generator.
Highlights
- 55 language lexers — Hand-written state machines for Python, JavaScript, Rust, Go, and 51 more
- O(n) guaranteed — Linear time complexity, zero ReDoS vulnerabilities
- Python 3.14t optimized — Designed for free-threading (PEP 703) with declared GIL-free safety
- Pygments compatible — Drop-in CSS class compatibility
- Parallel API —
highlight_many()andtokenize_many()for concurrent processing
Features
Core API
highlight()— Generate formatted output with syntax highlightingtokenize()— Get raw tokens for custom processinghighlight_many()— Parallel highlighting for multiple blockstokenize_many()— Parallel tokenization
Formatter Registry
get_formatter()— Get formatter by name or aliaslist_formatters()— List all supported formatterssupports_formatter()— Check formatter support
Built-in formatters:
- HTML — Semantic or Pygments-compatible CSS classes
- Terminal — ANSI-colored terminal output
- Null — No-op formatter for benchmarking
Lexer Registry
get_lexer()— Get lexer by name or aliaslist_languages()— List all supported languagessupports_language()— Check language support
Styling
- Semantic CSS classes (
.syntax-keyword,.syntax-function, etc.) - Pygments-compatible classes (
.k,.nf, etc.) - Line highlighting with
hl_lines - Line numbers with
show_linenos
Languages
55 languages supported:
| Category | Languages |
|---|---|
| Core | Python, JavaScript, TypeScript, JSON, YAML, TOML, Bash, HTML, CSS, Diff |
| Systems | C, C++, Rust, Go, Zig, CUDA |
| JVM | Java, Kotlin, Scala, Groovy, Clojure |
| Scripting | Ruby, Perl, PHP, Lua, R, PowerShell |
| Functional | Haskell, Elixir |
| Modern | Dart, Julia, Nim, Gleam, V, Mojo, Triton |
| Config | INI, Nginx, Dockerfile, Makefile, HCL, CUE, Pkl |
| And more... | Swift, SQL, GraphQL, Markdown, XML, Protobuf, CSV, Stan, etc. |
Installation
pip install rosettes
Requires Python 3.14+.
Quick Start
from rosettes import highlight
# HTML output (default)
html = highlight("def hello(): print('world')", "python")
# Terminal output
ansi = highlight("def hello(): print('world')", "python", formatter="terminal")
# Parallel processing
from rosettes import highlight_many
blocks = [
("def foo(): pass", "python"),
("const x = 1;", "javascript"),
]
results = highlight_many(blocks)
Known Limitations
- 55 languages (vs Pygments' 500+)
- Python 3.14+ required