Registry / serialization / pygments-ansi-color

pygments-ansi-color

JSON →
library0.3.0pypypi✓ verified 88d ago

Pygments ANSI Color (version 0.3.0) provides a Pygments lexer specifically designed to highlight ANSI escape codes for colors and styles. It allows Pygments to correctly render colored terminal output, making it readable and formatted. The library has a slow release cadence, with the last update in September 2022, but remains functional for its intended purpose.

pip install pygments-ansi-color
INSTALL
IMPORT
SIG · PYGMENTS-ANSI-COLO
P
pygments-ansi-color
serializationpythonv0.3.0
Install
2.2s avg
Import
106ms
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 v0.3.0 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.113s · 26.4MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 2.2s · import 0.099s · 27MB
25MB installed
● package 25MB
Code
Verified usage

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

AnsiColorLexer
✓ from pygments_ansi_color import AnsiColorLexer

This quickstart demonstrates how to use `AnsiColorLexer` with Pygments' `highlight` function and `TerminalFormatter` to render a string containing ANSI color codes directly to your terminal. Ensure your terminal supports ANSI escape sequences for colors to display correctly.

from pygments import highlight from pygments.formatters import TerminalFormatter from pygments_ansi_color import AnsiColorLexer # Example string with ANSI color codes ansi_string = "\u001b[31mError: Something went wrong!\u001b[0m \u001b[32mSuccess: Operation completed.\u001b[0m" # Highlight the string using AnsiColorLexer and output to terminal highlighted_output = highlight(ansi_string, AnsiColorLexer(), TerminalFormatter()) print(highlighted_output)
Debug
Known issues
gotchaThis library provides a Pygments *lexer*, not a standalone formatter. You still need a Pygments formatter (e.g., `TerminalFormatter` or `HtmlFormatter`) to render the highlighted output.
fix
Always combine `AnsiColorLexer()` with a Pygments formatter like `highlight(code, AnsiColorLexer(), TerminalFormatter())`.
affects: All versions
gotchaThe `Pygments` library itself is a required dependency for `pygments-ansi-color` to function, but it may not be automatically installed. You might need to install `Pygments` separately.
fix
Ensure `pip install Pygments` is run if you encounter `ModuleNotFoundError` for `pygments` modules.
affects: All versions
gotchaThe lexer primarily focuses on ANSI color and style codes. It may not fully parse or render all complex ANSI escape sequences (e.g., cursor manipulation, advanced screen control codes) that are not directly related to text styling.
fix
Assume support primarily for `\u001b[...m` sequences for color and style. For other ANSI features, manual parsing or a different specialized library might be necessary.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pygments_ansi_color'
The 'pygments-ansi-color' library is not installed in the current Python environment.
fix
Run `pip install pygments-ansi-color` to install the library.
NameError: name 'AnsiColorLexer' is not defined
The `AnsiColorLexer` class was used in the code without being imported first.
fix
Add `from pygments_ansi_color import AnsiColorLexer` at the top of your Python script.
Output shows raw ANSI escape codes instead of colored text.
The Pygments formatter being used does not render ANSI escape codes for the specific output environment, or the terminal itself doesn't support them.
fix
Ensure you are using a Pygments formatter like `TerminalFormatter` for terminal output and that your terminal emulator is configured to display ANSI colors. Example: `highlight(code, AnsiColorLexer(), TerminalFormatter())`.
Upgrade
Version history
0.3.0latest on PyPI · released May 18, 2023
Audit
Dependencies
PygmentsrequiredRequired for core functionality, as this library provides a lexer that integrates with Pygments.
Agent activity
2 hits · last 30 days
node
2
Resources
pygments-ansi-color — pip install pygments-ansi-color · libregistry