Install & Compatibility
Where this runs
tested against v0.1.2 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 26.3MB
glibcpy 3.10–3.920 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.
AnsibleOutputLexer
✓ from ansible_pygments import AnsibleOutputLexer
✗ from ansible_pygments import AnsibleOutputLexer
This quickstart demonstrates how to use the `ansible-output` lexer with Pygments to highlight a string containing Ansible output and render it as HTML.
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
ansible_output = """
[WARNING]: Unable to find '/nosuchfile' in expected paths (use -vvvvv to see paths)
ok: [localhost] => {
"msg": "Hello from Ansible!"
}
"""
try:
lexer = get_lexer_by_name('ansible-output')
formatter = HtmlFormatter()
highlighted_html = highlight(ansible_output, lexer, formatter)
print(highlighted_html)
except Exception as e:
print(f"Error highlighting: {e}")
print("Make sure 'ansible-pygments' and 'Pygments' are installed.")
Debug
Known issues
gotchaPygments, and by extension `ansible-pygments`, can be susceptible to Denial-of-Service (DoS) attacks if processing arbitrary, untrusted user inputs. Crafted inputs might lead to long processing times or excessive memory usage.fixWhen highlighting untrusted user input, ensure Pygments processes are terminated after a reasonable timeout and limit concurrent processes to prevent resource exhaustion.
affects: All versions
gotchaAs a 0.x.x version library, while actively maintained, `ansible-pygments` may introduce minor API changes or breaking modifications between patch or minor versions without adhering to strict semantic versioning (e.g., a 0.1.x to 0.2.x bump might include breaking changes).fixPin `ansible-pygments` to exact versions in production environments (e.g., `ansible-pygments==0.1.2`) and review release notes carefully before upgrading.
affects: All 0.x.x versions
Upgrade
Version history
0.1.2latest on PyPI · released Jul 5, 2025
Audit
Dependencies
PygmentsrequiredProvides the core syntax highlighting framework.