Registry / observability / colored-traceback

colored-traceback

JSON →
library0.4.2pypypi✓ verified 86d ago

Colored-traceback is a Python library that automatically colors uncaught exception tracebacks, aiming to improve readability in the terminal. The project is currently active, with its latest release (0.4.2) on July 13, 2024, but has an infrequent release cadence.

pip install colored-traceback
INSTALL
IMPORT
SIG · COLORED-TRACEBACK
C
colored-traceback
observabilitypythonv0.4.2
Install
2.1s avg
Import
122ms
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.129s · 26.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.1s · import 0.116s · 27MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

add_hook
import colored_traceback colored_traceback.add_hook()
from colored_traceback import add_hook # Direct import of add_hook is not the intended primary usage for activation.
The add_hook() function is typically called directly from the colored_traceback module to install the exception hook.
auto
import colored_traceback.auto
A convenience import that automatically calls add_hook().
always
import colored_traceback.always
A convenience import that automatically calls add_hook(always=True) to force color output even when stderr is piped.

This quickstart demonstrates how to activate colored tracebacks by simply importing `colored_traceback.auto`. Running this script will cause a `ZeroDivisionError` and display a colorized traceback in your terminal.

import colored_traceback.auto def cause_error(): return 1 / 0 def main(): print("Attempting to cause an error...") cause_error() if __name__ == "__main__": main()
Debug
Known issues
breakingPython 3.13 and newer versions introduce native colorized tracebacks. Using `colored-traceback` with Python 3.13+ may lead to unexpected behavior, double coloring, or conflicts with the built-in system.
fix
On Python 3.13+, consider removing `colored-traceback` and relying on the interpreter's native colorization. If `colored-traceback` specific features are required, test thoroughly for conflicts or ensure native coloring is disabled if possible via `PYTHON_COLORS=0` or `NO_COLOR` environment variables.
affects: Python 3.13+
gotchaTracebacks may not appear colored when the output (stderr) is redirected or piped to another command/file.
fix
Use `colored_traceback.add_hook(always=True)` or `import colored_traceback.always` to force color output even when stderr is not a TTY.
affects: All versions
gotchaOn Windows, `colored-traceback` automatically installs the `colorama` package to provide ANSI escape sequence support, which might be an unexpected dependency for some users.
fix
Ensure `colorama` is installed if you encounter issues with coloring on Windows. If `colorama` is not desired, `colored-traceback` is not suitable for Windows environments requiring minimal dependencies.
affects: All versions on Windows
Errors
Common errors & fixes
Tracebacks appear with unexpected or double coloring on Python 3.13+.
Conflict with Python 3.13's built-in colored traceback feature.
fix
Remove `colored-traceback` from your environment if using Python 3.13 or newer, or investigate methods to disable Python's native colorization if you prefer `colored-traceback`'s output.
Tracebacks are monochrome (not colored) when running my script and piping output to another tool or saving to a file.
By default, `colored-traceback` disables color output when `stderr` is not detected as an interactive terminal (TTY).
fix
Modify your activation call to `colored_traceback.add_hook(always=True)` or use the convenience import `import colored_traceback.always`.
AttributeError: module 'colored_traceback' has no attribute 'auto' (or 'always' or 'add_hook')
Incorrect import statement or a damaged/incomplete installation.
fix
Ensure you are importing correctly as `import colored_traceback.auto`, `import colored_traceback.always`, or `import colored_traceback` followed by `colored_traceback.add_hook()`. If the issue persists, try reinstalling the package: `pip uninstall colored-traceback && pip install colored-traceback`.
Upgrade
Version history
0.4.2latest on PyPI · released Jul 13, 2024
Audit
Dependencies
pygmentsrequiredUsed for syntax highlighting the traceback output.
coloramaoptionalProvides cross-platform ANSI escape sequence support for terminals, automatically installed on Windows.
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
colored-traceback — pip install colored-traceback · libregistry