Pygments

Generic syntax highlighter for Python supporting over 500 languages and formats

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
73 /100 Good
Development Activity 56
Maintenance 56
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
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 5 days ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,823

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
Python
82%
AGPL 3.0

SearXNG

Search

38,786

Privacy-first metasearch engine that aggregates results from 250+ search services — no tracking, no profiling, full control when self-hosted.

View details
80
Repo Health
82
Technical
73
Dependency
Built with
Python 82%
Updated 6 days ago
Python
94%
Apache 2.0

SWIRL

Data Engineering · Databases · Search

3,046

Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.

View details
61
Repo Health
83
Technical
65
Dependency
Built with
Python 94%
Updated 1 weeks ago
Python
97%
MPL 2.0

Taiga Back

Developer Tools · Project Management

859

Self-hosted agile project management backend with Scrum, Kanban, issue tracking, and a full REST API — built on Django and PostgreSQL.

View details
72
Repo Health
74
Technical
64
Dependency
Built with
Python 97%
Updated 1 months ago
Go
94%
MIT

Traefik

Automation · Devops · Security

65,344

A cloud-native reverse proxy and load balancer that auto-configures itself from Docker, Kubernetes, and other orchestrators — zero manual routing required.

View details
93
Repo Health
85
Technical
64
Dependency
Built with
Go 94%
Updated 6 days ago
Python
92%
GPL 3.0

Weblate

Developer Tools

6,124

Continuous localization platform that commits translations directly into your version control system with full translator attribution.

View details
95
Repo Health
86
Technical
67
Dependency
Built with
Python 92%
Updated 5 days 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