ANSI - ANSI Cursor Movement and Graphics
raw JSON → 0.3.7 verified Fri May 01 auth: no python maintenance
A lightweight Python library for producing ANSI terminal control sequences, including cursor movement, color (8-bit and 24-bit True Color), and graphics. Current stable version is 0.3.7, released in October 2023. Maintenance mode; infrequent releases.
pip install ansi Common errors
error AttributeError: module 'ansi' has no attribute 'Cursor' ↓
cause The top-level __init__.py does not import Cursor by default in some older versions.
fix
Use 'from ansi.cursor import Cursor' or upgrade to >=0.3.5 where the fix is applied.
error ImportError: cannot import name 'Fore' from 'ansi' ↓
cause Fore is not available in very old versions (pre-0.3.0).
fix
Upgrade to latest version: pip install --upgrade ansi
Warnings
deprecated Python 2 and Python <3.7 are no longer supported. The rgb() function only accepts integers, not strings. ↓
fix Ensure Python >=3.7; pass integers to rgb(), e.g., rgb(255,0,0) not rgb('255','0','0')
gotcha The package does not automatically reset terminal attributes; you must explicitly use RESET codes. ↓
fix Add Fore.RESET or Cursor.RESET after your output, or use context managers if available.
Imports
- Cursor wrong
from ansi.cursor import Cursorcorrectfrom ansi import Cursor - Fore wrong
from ansi.color import Forecorrectfrom ansi import Fore
Quickstart
from ansi import Cursor, Fore, EscapeCode
cursor = Cursor()
print(cursor.up(1) + Fore.RED + 'Hello in red' + Fore.RESET)