{"id":2439,"library":"colorclass","title":"Colorclass","description":"Colorclass is a Python library for creating colorful and worry-free console applications, providing ANSI color text support for Linux, Mac OS X, and Windows. It includes 'auto colors' functionality to adapt to dark/light terminals. The current stable version is 2.2.2, released in December 2021, and it is actively maintained.","status":"active","version":"2.2.2","language":"en","source_language":"en","source_url":"https://github.com/matthewdeanmartin/colorclass","tags":["console","terminal","color","cli","ansi"],"install":[{"cmd":"pip install colorclass","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"While Color returns a ColoredString instance, users typically import and use the Color factory class directly to create colored strings.","wrong":"from colorclass import ColoredString","symbol":"Color","correct":"from colorclass import Color"},{"note":"Required for enabling ANSI color support on Windows terminals.","symbol":"Windows","correct":"from colorclass import Windows"},{"note":"Use to discover all available color and style tags.","symbol":"list_tags","correct":"from colorclass import list_tags"}],"quickstart":{"code":"from colorclass import Color, Windows, list_tags\nimport os\n\n# Enable Windows console support (required for colors on Windows)\n# Check if running on CI/CD or in a non-interactive environment\nif os.name == 'nt' and os.environ.get('CI') != 'true' and os.isatty(1):\n    Windows.enable()\n\n# Print a simple colored string\nprint(Color('{red}This text is red.{/red}'))\n\n# Combine multiple colors and styles\nprint(Color('{autoblue}{bgwhite}Blue text on white background.{/bgwhite}{/autoblue}'))\n\n# Use auto colors for terminals\nprint(Color('{autoyellow}This text adapts to terminal background.{/autoyellow}'))\n\n# List available tags\nprint('\\nAvailable tags:')\nfor tag in sorted(list_tags()):\n    print(f'- {tag}')","lang":"python","description":"This quickstart demonstrates how to import and use the `Color` class to apply colors and styles using curly-bracket tags. It also shows how to enable Windows console support and list all available tags. The `Windows.enable()` call is conditionally applied to avoid issues in CI/CD or non-interactive environments."},"warnings":[{"fix":"Add `from colorclass import Windows` and `Windows.enable()` at the start of your script if running on Windows.","message":"On Windows, ANSI color codes are not enabled by default for older terminals. You must call `Windows.enable()` in your application to properly display colors. Even on modern Windows 10/11, it's recommended for auto-color detection.","severity":"gotcha","affected_versions":"All versions on Windows"},{"fix":"Use `isinstance(obj, str)` (Python 3 compatible) or `isinstance(obj, (str, unicode))` for cross-version compatibility if strict type checking is necessary. Generally, relying on duck typing is preferred.","message":"In Python 2.x, `colorclass` string objects subclass `unicode`, whereas in Python 3.x, they subclass `str`. This might lead to compatibility issues if your code explicitly checks types using `isinstance(obj, unicode)` or `isinstance(obj, str)` without considering the Python version.","severity":"breaking","affected_versions":"Between Python 2.x and Python 3.x environments"},{"fix":"Be aware of these environment variables (`COLOR_DISABLE`, `COLOR_ENABLE`) if colors are not appearing as expected in piped contexts. They take precedence over other settings.","message":"When `colorclass` is used via piped command line (`python -m colorclass`), environment variables like `COLOR_DISABLE=true` or `COLOR_ENABLE=true` can override automatic color detection, forcing colors off or on, respectively.","severity":"gotcha","affected_versions":"All versions when used via command line pipe"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}