{"id":6290,"library":"types-termcolor","title":"Typing stubs for termcolor","description":"This is a PEP 561 type stub package for the 'termcolor' library, providing external type annotations for static analysis tools like mypy, pyright, and PyCharm. The current version is 1.1.6.2, released on March 27, 2023. These stub packages are automatically generated and released by the typeshed internal machinery, typically on a daily cadence, ensuring up-to-date type information for various Python libraries.","status":"active","version":"1.1.6.2","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type hints","termcolor","console","terminal","color"],"install":[{"cmd":"pip install types-termcolor","lang":"bash","label":"Install types-termcolor"}],"dependencies":[{"reason":"`types-termcolor` provides type stubs for the `termcolor` package; it does not offer runtime functionality itself. It is only beneficial if the `termcolor` library is also installed in your environment.","package":"termcolor","optional":false}],"imports":[{"note":"The `types-termcolor` package provides type information for symbols imported from the `termcolor` library. You do not directly import from `types-termcolor`.","symbol":"colored","correct":"from termcolor import colored"},{"note":"The `types-termcolor` package provides type information for symbols imported from the `termcolor` library. You do not directly import from `types-termcolor`.","symbol":"cprint","correct":"from termcolor import cprint"}],"quickstart":{"code":"from termcolor import colored, cprint\nimport sys\n\n# Basic usage of 'colored'\nprint(colored('Hello, World!', 'red'))\n\n# Using 'colored' with background color and multiple attributes\ntext_with_attributes = colored(\n    \"Hello, beautifully colored World!\",\n    \"green\",\n    \"on_red\",\n    attrs=[\"bold\", \"underline\"]\n)\nprint(text_with_attributes)\n\n# Using 'cprint' for direct printing\ncprint(\"This is a blue and bold message.\", \"blue\", attrs=[\"bold\"])\n\n# Example with error handling, printing to stderr in red\ntry:\n    raise ValueError(\"Something went wrong during processing!\")\nexcept ValueError as e:\n    cprint(f\"Error: {e}\", \"white\", \"on_red\", attrs=[\"bold\"], file=sys.stderr)\n","lang":"python","description":"This quickstart demonstrates how to use the `colored` function and `cprint` from the `termcolor` library to output text with foreground colors, background highlights, and text attributes to the terminal. When `types-termcolor` is installed, it enables type checkers to provide hints and validate the usage of these functions, improving code quality and readability."},"warnings":[{"fix":"Uninstall `types-termcolor` by running `pip uninstall types-termcolor`. Ensure your type checker is configured to use the inline types from `termcolor`.","message":"If you are using `termcolor` version 2.0.0 or newer, you should uninstall `types-termcolor`. As of version 2.0.0, the `termcolor` package includes its own inline type annotations, making this stub package redundant and potentially causing conflicts or issues with type checkers.","severity":"breaking","affected_versions":"termcolor>=2.0.0"},{"fix":"Ensure the `termcolor` library is installed alongside `types-termcolor` by running `pip install termcolor`.","message":"The `types-termcolor` package provides *only* type stubs; it does not contain the runtime code for the `termcolor` library itself. Your program will not execute correctly without the actual `termcolor` library installed.","severity":"gotcha","affected_versions":"all"},{"fix":"Use a modern terminal emulator (e.g., Windows Terminal, most Linux/macOS terminals, VS Code integrated terminal). When piping output, some tools like `less` may require a `-r` flag to interpret raw ANSI escape sequences (e.g., `python script.py | less -r`).","message":"`termcolor` relies on ANSI escape codes to produce colored output in the terminal. Not all terminals (e.g., older Windows Command Prompt or when piping output to certain tools) support these codes, which can result in raw escape sequences being printed instead of the intended colored text.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using flexible version specifiers for stub packages (e.g., `types-termcolor>=1.1,<1.2` if `termcolor>=1.1,<1.2` is used). Regularly review and update pinned stub versions to leverage improvements and maintain compatibility.","message":"Typeshed stub packages, including `types-termcolor`, use a versioning scheme where parts of the version number correlate to the runtime package's version. While this aims for compatibility, aggressively pinning stub package versions might lead to incompatibilities if the runtime `termcolor` package updates independently, or cause you to miss valuable type stub improvements.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}