{"id":9467,"library":"ansimarkup","title":"AnsiMarkup","description":"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.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/gvalkov/python-ansimarkup","tags":["terminal","cli","colors","formatting","ansi","markup"],"install":[{"cmd":"pip install ansimarkup","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"AnsiMarkup","correct":"from ansimarkup import AnsiMarkup"},{"note":"Useful for direct printing to a stream with markup.","symbol":"ansiprint","correct":"from ansimarkup import ansiprint"},{"note":"`strip_markup` was removed in 2.0.0, replaced by `ansimarkup.strip`.","wrong":"from ansimarkup import strip_markup","symbol":"strip","correct":"from ansimarkup import strip"}],"quickstart":{"code":"from ansimarkup import AnsiMarkup\n\n# Create an AnsiMarkup instance\nam = AnsiMarkup()\n\n# Use the parse method to convert markup to ANSI colored text\ntext = am.parse(\"<red>Error:</red> <bold>Something went wrong!</bold>\")\nprint(text)\n\n# Or, use ansiprint for direct output\nfrom ansimarkup import ansiprint\nansiprint(\"<green>Success:</green> Operation complete!\")","lang":"python","description":"Demonstrates initializing AnsiMarkup to parse text and using `ansiprint` for direct output, showcasing basic colored and styled text."},"warnings":[{"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)`.","message":"Major API changes in AnsiMarkup 2.0.0 removed direct callability of `AnsiMarkup` instances and arguments like `stdout`/`stream` from the constructor and `parse` method.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace calls to `AnsiMarkup().strip_markup(text)` or `ansimarkup.strip_markup(text)` with `from ansimarkup import strip; strip(text)`.","message":"The `strip_markup` function/method was removed from the `AnsiMarkup` class and `ansimarkup` module namespace in version 2.0.0.","severity":"breaking","affected_versions":">=2.0.0"},{"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)`.","message":"Tag case-sensitivity changed in AnsiMarkup 2.0.0. Tags are now case-sensitive by default.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Explicitly use the `parse` method: `am.parse(\"<red>Error</red>\")` instead of `am(\"<red>Error</red>\")`.","cause":"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.","error":"TypeError: 'AnsiMarkup' object is not callable"},{"fix":"Import and use the new standalone `strip` function: `from ansimarkup import strip; plain_text = strip(\"<bold>Markup</bold>\")`.","cause":"The `strip_markup` function was removed from the top-level `ansimarkup` module and `AnsiMarkup` class in version 2.0.0.","error":"NameError: name 'strip_markup' is not defined"},{"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.","cause":"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.","error":"My terminal output shows raw ANSI escape codes or no colors at all."}]}