Registry / serialization / ansimarkup

ansimarkup

JSON →
library2.2.0pypypi✓ verified 85d ago

Ansimarkup is a Python library that simplifies producing colored and styled terminal text using an XML-like markup syntax. It translates tags like `<red>Hello</red>` into appropriate ANSI escape codes, supporting various colors, styles (bold, italic, underline), and background colors. The library is currently at version 2.2.0, with stable, albeit infrequent, releases.

pip install ansimarkup
INSTALL
IMPORT
SIG · ANSIMARKUP
A
ansimarkup
serializationpythonv2.2.0
Install
1.6s avg
Import
28ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.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.103.910 runs
installs and imports cleanly · install 0.0s · import 0.022s · 18.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.033s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

AnsiMarkup
from ansimarkup import AnsiMarkup
ansiprint
from ansimarkup import ansiprint
Useful for direct printing to a stream with markup.
strip
from ansimarkup import strip
from ansimarkup import strip_markup
`strip_markup` was removed in 2.0.0, replaced by `ansimarkup.strip`.

Demonstrates initializing AnsiMarkup to parse text and using `ansiprint` for direct output, showcasing basic colored and styled text.

from ansimarkup import AnsiMarkup # Create an AnsiMarkup instance am = AnsiMarkup() # Use the parse method to convert markup to ANSI colored text text = am.parse("<red>Error:</red> <bold>Something went wrong!</bold>") print(text) # Or, use ansiprint for direct output from ansimarkup import ansiprint ansiprint("<green>Success:</green> Operation complete!")
Debug
Known issues
breakingMajor API changes in AnsiMarkup 2.0.0 removed direct callability of `AnsiMarkup` instances and arguments like `stdout`/`stream` from the constructor and `parse` method.
fix
Instead of `am('text')`, use `am.parse('text')`. For direct printing to a stream, use the `ansiprint` function. If you need a custom stream for parsing, pass it to the `AnsiMarkup` constructor: `AnsiMarkup(stream=my_stream)`.
affects: >=2.0.0
breakingThe `strip_markup` function/method was removed from the `AnsiMarkup` class and `ansimarkup` module namespace in version 2.0.0.
fix
Replace calls to `AnsiMarkup().strip_markup(text)` or `ansimarkup.strip_markup(text)` with `from ansimarkup import strip; strip(text)`.
affects: >=2.0.0
gotchaTag case-sensitivity changed in AnsiMarkup 2.0.0. Tags are now case-sensitive by default.
fix
Ensure consistent casing for your tags (e.g., always `<red>` not `<Red>`). If you require case-insensitive tags for backwards compatibility, initialize `AnsiMarkup(case_sensitive=False)`.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: 'AnsiMarkup' object is not callable
In `ansimarkup` versions 2.0.0 and above, `AnsiMarkup` instances are no longer directly callable like a function. This was a deprecated feature in 1.x and removed in 2.x.
fix
Explicitly use the `parse` method: `am.parse("<red>Error</red>")` instead of `am("<red>Error</red>")`.
NameError: name 'strip_markup' is not defined
The `strip_markup` function was removed from the top-level `ansimarkup` module and `AnsiMarkup` class in version 2.0.0.
fix
Import and use the new standalone `strip` function: `from ansimarkup import strip; plain_text = strip("<bold>Markup</bold>")`.
My terminal output shows raw ANSI escape codes or no colors at all.
The terminal you are using may not support ANSI escape codes, or the output is being redirected (e.g., to a file, pipe, or non-interactive environment) where `ansimarkup` might disable colors by default.
fix
Ensure you are running in an ANSI-compatible terminal (e.g., most Linux/macOS terminals, modern Windows Terminal). If you need to force colors even when output is redirected, you can initialize `AnsiMarkup(force_colors=True)`. However, this might result in raw escape codes in truly incompatible environments or files.
Upgrade
Version history
2.2.0latest on PyPI · released Feb 4, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
ansimarkup — pip install ansimarkup · libregistry