ansimarkup
Produce colored terminal text with an xml-like markup
What it is and what it does
Ansimarkup is a lightweight wrapper around colorama that lets you write colored and styled terminal output using simple XML-like tags instead of raw ANSI escape codes. You write markup like `<b><red>text</red></b>` and it converts to the corresponding terminal escape sequences. It supports foreground and background colors (named, xterm, hex, and RGB), text styles like bold and dim, nested tags, custom tag definitions, and a logging formatter for the standard library.
The package is designed for convenience with a focus on keeping processing minimal. It includes utilities like ansistring for proper text alignment when using formatted strings, a strip() method to remove markup, and a strict mode to catch mismatched tags. It also works from the command line and on Windows (with colorama initialization). The main limitation is that it does little validation of markup structure—unbalanced nesting will produce incorrect output rather than raising an error.
Use it for:
- Build CLI tools with colored help text, error messages, and status output using readable markup instead of escape codes.
- Add colored logging output to Python applications via the included AnsiMarkupFormatter for the logging module.
- Format terminal progress indicators, warnings, and alerts with different colors and styles for better visibility.
- Create shell-like scripts in Python that need readable, maintainable colored text without managing raw escape sequences.
- Align and format colored terminal tables or reports where the delta property helps account for escape sequence length.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Ansimarkup converts XML-like markup tags into ANSI escape sequences for colored and styled terminal text output.
Yes, if you need readable colored terminal output without managing raw escape codes. The low install friction, permissive license, stable classifier, and zero known vulnerabilities make it a safe choice. The aging maintenance status (last commit 191 days ago) is not a blocker for a stable, focused utility, but verify that its known limitations around unbalanced nesting don't affect your use case.
Install
ansimarkup on PyPI
pip
pip install ansimarkupuv
uv add ansimarkuppoetry
poetry add ansimarkupInstalling ansimarkup
Before you install
Low install friction with a single runtime dependency on colorama. The package is in aging maintenance status with a last commit on 2026-02-04, but carries a Production/Stable classifier and no known vulnerabilities.
License in practice
Released under the BSD 3-Clause License (permissive), which allows commercial and private use with minimal restrictions—only requiring preservation of copyright notice and disclaimer.
Quickstart
from ansimarkup import parse, ansiprint
# Parse markup tags to ANSI escape sequences
result = parse("<b><r>bold red text</r></b>")
print(result)
# Or use ansiprint directly
ansiprint("<b><r>bold red text</r></b>")
On Windows, colorama.init() should be called first to enable ANSI escape sequence support.
Verify before relying
- Whether the package handles all edge cases beyond the 'happy paths' mentioned in its own limitations section.
- Current test coverage and whether corner cases like unbalanced nesting are adequately tested.
Package facts
| License | BSD 3-Clause License Copyright (c) 2017, Georgi Valkov. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — colorama |
| Maintenance | aging — 191 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 158,660/month — #10,714 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ansimarkup-2.2.0-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
termcolorAdds ANSI color and text formatting (bold,…
permissive · top 1,000 on PyPI
ansicolorsEmbeds ANSI color and style codes into Python…
permissive · top 5,000 on PyPI
ansi2htmlConverts terminal output with ANSI color codes…
copyleft · top 5,000 on PyPI
simple-colorsAdds colored and styled text output to terminal…
unclear · top 15,000 on PyPI
ansiProvides ANSI escape codes for cursor movement…
permissive · top 15,000 on PyPI
ascii-colorsUnified terminal UI library providing colored…
permissive · top 15,000 on PyPI
pastelPastel adds colored text output to terminal…
permissive · top 5,000 on PyPI
coloramaColorama makes ANSI escape sequences for…
permissive · top 100 on PyPI
coloredlogsAdds colored output to Python's standard…
permissive · top 1,000 on PyPI
pansiPansi provides a clean interface for rendering…
permissive · top 15,000 on PyPI