Typing stubs for Pygments

2.20.0.20260408 · active · verified Thu Apr 09

types-pygments is a PEP 561 type stub package providing external type annotations for the Pygments library. It enables static type checkers like MyPy and PyCharm to verify code that uses Pygments. This package, currently at version 2.20.0.20260408, is part of the typeshed project and is regularly updated, often daily, to reflect changes in the underlying Pygments library.

Warnings

Install

Imports

Quickstart

This example demonstrates basic usage of Pygments for syntax highlighting. When 'types-pygments' is installed alongside 'Pygments', a static type checker can analyze this code for type consistency, leveraging the provided stub files.

from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter

code = 'print("Hello, world!")'

# Highlight the code
highlighted_code = highlight(code, PythonLexer(), HtmlFormatter())

print(highlighted_code)

# To verify types with a checker like MyPy, save this to a .py file and run:
# mypy your_file_name.py
# The 'types-pygments' package provides the necessary type hints for the above operations.

view raw JSON →