ansi2html
Convert text with ANSI color codes to HTML or to LaTeX
What it is and what it does
ansi2html is a utility for converting terminal text containing ANSI color and formatting codes into HTML or LaTeX markup. It works both as a Python library (via the Ansi2HTMLConverter class) and as a command-line tool, making it useful for capturing colored terminal output and rendering it in web pages or documents. The package depends on importlib-metadata and typing-extensions, both lightweight standard-library backports.
Typical use cases include converting colored log output to HTML for web display, converting task runner output to shareable HTML, or piping colored command output through the tool to preserve formatting. It has been actively maintained since its first release in 2010, supports Python 3.7 through 3.12, and carries no known security vulnerabilities.
Use it for:
- Convert colored log files to HTML for web-based log viewing and archival
- Pipe colored CLI tool output through ansi2html to create shareable HTML reports
- Preserve terminal colors when exporting test runner or build tool output to HTML
- Convert colored task management or monitoring tool output to LaTeX for documentation
- Generate HTML versions of colored terminal sessions for documentation or tutorials
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts terminal output with ANSI color codes to HTML or LaTeX, preserving colors and formatting for display in browsers or documents.
Yes. ansi2html is a stable, actively maintained utility with no known vulnerabilities, low install friction, and a clear single purpose. The copyleft LGPLv3+ license is appropriate for open-source projects and most internal use; proprietary projects should verify compatibility. Install it if you need to convert ANSI-colored terminal output to HTML or LaTeX.
Install
ansi2html on PyPI
pip
pip install ansi2htmluv
uv add ansi2htmlpoetry
poetry add ansi2htmlInstalling ansi2html
Before you install
Low friction install with minimal dependencies. Active maintenance with recent commits as of 2026-08-03 and stable production status.
License in practice
Licensed under LGPLv3+, a copyleft license requiring derivative works to remain open-source under the same terms. Suitable for open-source projects; proprietary use requires careful review.
Quickstart
pip install ansi2html
from ansi2html import Ansi2HTMLConverter
conv = Ansi2HTMLConverter()
html = conv.convert(ansi_text)
Verify before relying
- Whether LaTeX output preserves all ANSI color codes or only a subset
- Performance characteristics with very large ANSI-colored outputs
- Specific ANSI codes or color ranges supported by the converter
Package facts
| License | LGPLv3+ (copyleft) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — importlib-metadata, typing-extensions |
| Maintenance | actively maintained — 783 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,302,559/month — #3,155 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ansi2html-1.9.2-py3-none-any.whl
Keywords: ansi, html, color
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
ansi2txtConverts ANSI escape sequences (color codes,…
unclear · top 15,000 on PyPI
strip-ansiRemoves ANSI escape sequences (color codes,…
unclear · top 15,000 on PyPI
ansiProvides ANSI escape codes for cursor movement…
permissive · top 15,000 on PyPI
ansicolorsEmbeds ANSI color and style codes into Python…
permissive · top 5,000 on PyPI
crayonsCrayons provides colored text output for…
permissive · top 15,000 on PyPI
ansimarkupAnsimarkup converts XML-like markup tags into…
permissive · top 15,000 on PyPI
coloredColored provides ANSI/VT100 escape sequences…
permissive · top 5,000 on PyPI
rst2ansiConverts reStructuredText documents to…
permissive · top 15,000 on PyPI
termcolorAdds ANSI color and text formatting (bold,…
permissive · top 1,000 on PyPI
pylatexencConverts between LaTeX code and Unicode text in…
permissive · top 5,000 on PyPI