Pygments

Generic syntax highlighter for Python supporting over 500 languages and formats

Library
PyPI
v2.21.0
2,211 stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 100
Maintenance 84
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
84 /100 Excellent
Architecture 85
Code Quality 88
Innovation 78
Learning Curve 85

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 pygmentize CLI 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

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 4 days ago
Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

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.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 4 days ago
Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,125

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
61
Dependency
Built with
Python 59%
Jupyter Notebook 21%
Updated 1 weeks ago
Python
84%
Other

Bugsink

Developer Tools · Monitoring

2,095

Self-hosted error tracking that accepts Sentry SDKs out of the box, so you keep your instrumentation and drop the monthly bill.

View details
84
Repo Health
80
Technical
71
Dependency
Built with
Python 84%
HTML 14%
Updated 1 weeks ago
C++
68%
Apache 2.0

ClickHouse

Analytics · Data Engineering · Databases

50,116

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
64
Dependency
Built with
C++ 68%
Python 14%
Updated 4 days ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

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.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
TypeScript
96%
MIT

deepseek-harness

AI Agents · AI Development · Developer Tools

237,945

An open-source, plugin-based agent harness from DeepSeek AI that runs coding and automation agents across web, desktop, CLI, and SDK surfaces.

View details
81
Repo Health
89
Technical
74
Dependency
Built with
TypeScript 96%
Updated 5 days ago
Go
49%
MIT

Dokku

Devops · Hosting Control Panel

32,162

The smallest PaaS implementation you've ever seen — deploy apps via git push using Docker and Heroku buildpacks on your own server.

View details
92
Repo Health
85
Technical
66
Dependency
Built with
Go 49%
Shell 48%
Updated 6 days ago
Python
86%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,541

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
82
Repo Health
75
Technical
66
Dependency
Built with
Python 86%
HTML 14%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers