Pygments
Generic syntax highlighter for Python supporting over 500 languages and formats
Repository Health
Technical Analysis
Pygments is a generic syntax highlighter written in pure Python. It supports more than 500 languages and text formats, converting source code into richly marked-up output (HTML, LaTeX, RTF, terminal ANSI, and more) for use in code hosting platforms, documentation generators, forums, wikis, and any application that needs to prettify source code.
The library is built around a pluggable lexer/formatter/style architecture: lexers tokenize source text into a stream of typed tokens, formatters render that token stream into a target output format, and styles control the color/markup applied to each token type. This separation of concerns lets Pygments support an enormous range of languages while keeping each individual lexer small and focused, and it has made the project a de facto standard dependency behind tools like Sphinx, Jupyter, and countless static site generators.
What You Get
- Over 500 built-in lexers covering mainstream and extremely niche programming, markup, and configuration languages
- Multiple output formatters: HTML (with CSS classes or inline styles), ANSI terminal, LaTeX, RTF, SVG, and raw image output via Pillow
- A large library of bundled color styles (Monokai, Solarized, Dracula-compatible themes, etc.) plus a style API for custom themes
- The
pygmentizeCLI for highlighting files or piping code from stdin without writing any Python - A plugin/extension system so third-party packages can register additional lexers, formatters, filters, and styles
- Filters for transforming token streams (e.g. stripping whitespace, adding line numbers, highlighting specific lines)
Common Use Cases
- Highlighting code blocks in static site generators and documentation tools (Sphinx, MkDocs, Jekyll plugins)
- Rendering syntax-highlighted code snippets on code-hosting and forum/wiki platforms
- Producing colorized terminal output for CLI tools that display source code or diffs
- Generating print-ready or PDF documentation with LaTeX-formatted code listings
Under The Hood
Architecture Pygments’ core pipeline is Lexer → token stream → Formatter, with pygments.lex() and pygments.highlight() in pygments/__init__.py as the primary entry points. pygments/lexer.py defines the base Lexer, RegexLexer, and ExtendedRegexLexer classes, where each concrete lexer (under pygments/lexers/) declares a set of named states with regex-to-token-action rules; RegexLexer.get_tokens_unprocessed walks the input applying the current state’s rules and can push/pop lexer states, enabling handling of nested or context-sensitive syntax (e.g. embedded code blocks). pygments/formatter.py defines the abstract Formatter base that concrete formatters (pygments/formatters/) subclass to turn (token_type, value) pairs into markup, while pygments/style.py and pygments/styles/ define color themes as declarative token-to-style mappings that formatters consult when rendering. pygments/cmdline.py implements the pygmentize CLI, and pygments/plugin.py wires in the setuptools/importlib entry-point plugin system that lets external packages register lexers, formatters, styles, and filters without modifying the core package. Tech Stack Pygments is pure Python (supporting Python 3.9+ per pyproject.toml), built with the hatchling build backend, and has effectively zero required runtime dependencies — the only optional dependency is colorama for Windows terminal color support. The project vendors small amounts of non-Python code (Emacs Lisp, StringTemplate, C, and dozens of other sample languages) purely as lexer test fixtures/example files, not as build dependencies. Code Quality The tests/ directory is extensive, including test_basic_api.py, test_cmdline.py, an examplefiles/ corpus with real-world snippets in hundreds of languages used to exercise each lexer, and snippets/ for targeted regression tests; the project is also continuously fuzzed via OSS-Fuzz per the README, and the maintainers explicitly document their approach to catastrophic-backtracking regex risk. Code style is consistent across the 500+ lexer modules, following a shared template of tokens dicts and small mixin classes for reuse. API Design The primary API surface is deliberately tiny — highlight(code, lexer, formatter) plus get_lexer_by_name()/guess_lexer() and get_formatter_by_name() factory functions — making the common case a one-line call, while the Lexer/Formatter/Style base classes offer a well-documented extension path for anyone adding new languages or output formats.
Used by 19 apps in this directory
Agno
AI Development · Automation · Devops
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Apache Airflow
Data Engineering
Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.
argilla
AI Development · Data Engineering
Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.
Bugsink
Developer Tools · Monitoring
Self-hosted error tracking that accepts Sentry SDKs out of the box, so you keep your instrumentation and drop the monthly bill.
ClickHouse
Analytics · Data Engineering · Databases
Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.
CubeSandbox
AI Agents · Developer Tools · Security
Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.
deepseek-harness
AI Agents · AI Development · Developer Tools
An open-source, plugin-based agent harness from DeepSeek AI that runs coding and automation agents across web, desktop, CLI, and SDK surfaces.
Dokku
Devops · Hosting Control Panel
The smallest PaaS implementation you've ever seen — deploy apps via git push using Docker and Heroku buildpacks on your own server.
knowhere
AI Development · AI Memory · Developer Tools
Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.