{"id":2342,"library":"types-pygments","title":"Typing stubs for Pygments","description":"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.","status":"active","version":"2.20.0.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/main/stubs/Pygments","tags":["typing","stubs","type hints","pygments","typeshed"],"install":[{"cmd":"pip install types-pygments Pygments","lang":"bash","label":"Install stubs and runtime library"}],"dependencies":[{"reason":"Provides the runtime functionality that these stubs type-check. Users must install Pygments separately.","package":"Pygments","optional":false}],"imports":[{"note":"Types are provided for the Pygments library; direct imports from 'types-pygments' are not used for runtime functionality.","symbol":"highlight","correct":"from pygments import highlight"},{"note":"Types for Pygments lexers are provided through this stub package.","symbol":"PythonLexer","correct":"from pygments.lexers import PythonLexer"},{"note":"Types for Pygments formatters are provided through this stub package.","symbol":"HtmlFormatter","correct":"from pygments.formatters import HtmlFormatter"}],"quickstart":{"code":"from pygments import highlight\nfrom pygments.lexers import PythonLexer\nfrom pygments.formatters import HtmlFormatter\n\ncode = 'print(\"Hello, world!\")'\n\n# Highlight the code\nhighlighted_code = highlight(code, PythonLexer(), HtmlFormatter())\n\nprint(highlighted_code)\n\n# To verify types with a checker like MyPy, save this to a .py file and run:\n# mypy your_file_name.py\n# The 'types-pygments' package provides the necessary type hints for the above operations.","lang":"python","description":"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."},"warnings":[{"fix":"Ensure both 'Pygments' and 'types-pygments' are installed: `pip install Pygments types-pygments`.","message":"The '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.","severity":"gotcha","affected_versions":"All"},{"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.*'`.","message":"The 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.","severity":"breaking","affected_versions":"All"},{"fix":"Refer to the Pygments official documentation for runtime behavior. Consider contributing to typeshed if you find significant missing annotations that you can address.","message":"This 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}