Pansi

raw JSON →
2024.11.0 verified Fri May 01 auth: no python

Text mode rendering library for Python, version 2024.11.0, released monthly. Provides styled console output with support for colors, attributes, and basic terminal control.

pip install pansi
error ImportError: cannot import name 'Console' from 'pansi.console'
cause Incorrect import path for Console class. Console is exported from the top-level pansi module, not from pansi.console.
fix
Use 'from pansi import Console'.
error AttributeError: module 'pansi' has no attribute 'Style'
cause Old code using the import style 'import pansi; pansi.Style' may fail if the package was not correctly installed or if using a very old version (pre-2020.7.1).
fix
Ensure you have version 2020.7.1 or later and use the correct import: 'from pansi import Style'.
gotcha Import paths changed between v2020.7.0 and v2020.7.1. Prior to v2020.7.1, pansi was a single module; afterward it became a package. Old imports like 'from pansi import pansi' will break.
fix Update imports to use the new package structure: 'from pansi import Console' instead of 'from pansi import pansi'.
deprecated The 'six' dependency is likely to be removed in a future major release, breaking code that relies on implicit six imports.
fix Do not rely on six being available as a transitive dependency; install six explicitly if needed.

Create a Console instance and use writeln to output styled text with colors and styles.

from pansi import Console, Color, Style

# Create a Console that writes to stdout (default)
c = Console()

# Write styled text
c.writeln('Hello, World!', Color.GREEN)
c.writeln('Bold and red', Style.BRIGHT, Color.RED)