Home

Pyments

Pygments is a Python library for syntax highlighting. It provides a large collection of lexers for programming languages and other text formats, along with output formatters for rendering highlighted code. Although commonly known as Pygments, it is sometimes misspelled as Pyments.

The library is implemented in Python and is designed to be embedded in other Python applications or

Pygments supports many languages and output formats, including HTML, CSS, LaTeX, RTF, and ANSI terminal colors.

Installation is straightforward via Python's package manager: pip install pygments. The project is open source and

Usage example (brief): highlight('def foo(): pass', PythonLexer(), HtmlFormatter()) returns HTML containing syntax-highlighted code. Pygments thus serves

used
directly
from
the
command
line.
It
is
widely
used
in
documentation
systems
and
static
site
generators
to
display
source
code
with
color.
The
architecture
centers
on
three
concepts:
lexers,
which
tokenize
input;
formatters,
which
convert
tokens
to
the
desired
output;
and
styles,
which
map
token
types
to
colors.
It
integrates
with
projects
such
as
Sphinx,
Read
the
Docs,
Django,
and
various
static
site
tools
to
provide
consistent
syntax
highlighting.
A
command-line
tool
named
pygmentize
exposes
the
highlighting
capability
without
writing
Python
code.
distributed
under
a
BSD-style
license,
with
development
hosted
on
its
official
repository.
Developers
can
extend
Pygments
by
contributing
new
lexers,
formatters,
or
styles.
as
a
versatile,
extensible
solution
for
code
highlighting
across
environments.