Registry / type-stubs / types-pygments

types-pygments

JSON →
library2.21.0.20260819pypypi✓ verified 28d ago

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.

pip install types-pygments Pygments
INSTALL
IMPORT
SIG · TYPES-PYGMENTS
T
types-pygments
type-stubspythonv2.21.0.20260819
Install
2.2s avg
Import
—
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.21.0.20260819 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 26.7MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.2s · import 0.000s · 27MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

highlight
✓ from pygments import highlight
Types are provided for the Pygments library; direct imports from 'types-pygments' are not used for runtime functionality.
PythonLexer
✓ from pygments.lexers import PythonLexer
Types for Pygments lexers are provided through this stub package.
HtmlFormatter
✓ from pygments.formatters import HtmlFormatter
Types for Pygments formatters are provided through this stub package.

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.
Debug
Known issues
gotchaThe 'types-pygments' package provides *only* type annotations. It does not include the Pygments runtime library itself. You must install 'Pygments' separately for your code to function.
fix
Ensure both 'Pygments' and 'types-pygments' are installed: `pip install Pygments types-pygments`.
affects: All
breakingThe version of 'types-pygments' should ideally align with the major and minor version of your installed 'Pygments' library. For example, 'types-pygments==2.20.0.x' is designed for 'Pygments==2.20.*'. Using a significantly mismatched version might lead to inaccurate type checking results.
fix
Check the PyPI page for 'types-pygments' to see which Pygments versions it targets. Pin your 'types-pygments' version accordingly, e.g., `pip install 'Pygments==2.20.*' 'types-pygments==2.20.0.*'`.
affects: All
gotchaThis stub package is marked as 'partial'. This means not all parts of the Pygments library may have complete or perfectly accurate type annotations. You might encounter 'Any' types or missing annotations for less common functions/classes.
fix
Refer to the Pygments official documentation for runtime behavior. Consider contributing to typeshed if you find significant missing annotations that you can address.
affects: All
Upgrade
Version history
2.21.0.20260819latest on PyPI · released Aug 19, 2026
Audit
Dependencies
PygmentsrequiredProvides the runtime functionality that these stubs type-check. Users must install Pygments separately.
Agent activity
30 hits · last 30 days
node
26
OpenAI (training)
1
Resources
types-pygments — pip install types-pygments · libregistry