Registry /
testing / traceback-with-variables
Install & Compatibility
Where this runs
tested against v2.2.1 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.068s · 17.9MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.7s · import 0.062s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
print
✓ from traceback_with_variables import print
✗ import traceback_with_variables as tb_with_vars
format_exc
✓ from traceback_with_variables import format_exc
ColorScheme
✓ from traceback_with_variables import ColorScheme
This quickstart demonstrates how to globally activate `traceback-with-variables` and then trigger an error. When the `ZeroDivisionError` occurs, the enhanced traceback (including local variable values for each frame) will be printed to the console.
import traceback_with_variables as tb_with_vars
tb_with_vars.activate() # Globally activate the enhanced traceback
def f(a, b):
# This function will cause a ZeroDivisionError
return a / b
def g(x):
y = x * 2
# If x is 0, y will be 0, leading to ZeroDivisionError in f
if x == 0:
z = 1 # Avoid division by zero here just to show other vars
else:
z = x / y
return f(z, 0) # This division by zero will be caught
try:
g(1) # Call with a non-zero to trace normal flow then crash
except Exception as e:
print(f"Caught exception: {e}")
# The activate() call ensures sys.excepthook is set
# The standard traceback will now include variable values
# No explicit print_exc needed here for global hook
print("Check console for enhanced traceback.")
tb_with_vars.deactivate() # Optionally deactivate when done
Debug
Known issues
gotchaActivating `traceback-with-variables` globally via `activate()` or `activate_by_import` sets `sys.excepthook`. This can interfere with other libraries (e.g., logging frameworks, error reporting tools) that also modify the global exception handler, potentially overriding or being overridden.fixIf encountering conflicts, consider selectively applying `add_variables_to_traceback` as a decorator or context manager, or manually integrating `dump_traceback()` with your existing exception handling. Ensure `activate()` is called after other handlers if `traceback-with-variables` output is preferred.
affects: All versions
gotchaEnabling variable capturing globally in production environments can introduce performance overhead, especially for deep stack traces or large variable objects. Additionally, logging local variable values might expose sensitive data (e.g., API keys, user credentials) in logs.fixUse `traceback-with-variables` primarily in development/testing environments. In production, configure carefully, using `exclude_regex` for sensitive variables or applying it selectively (e.g., `add_variables_to_traceback` decorator) only to critical functions, or disable it entirely.
affects: All versions
breakingThe transition to v2.0.0 (and subsequent minor versions like v2.0.4) was not extensively documented with explicit breaking changes. However, major version bumps often imply potential changes to `activate()` parameters, default output formatting (e.g., with the introduction of `default_format`), or internal behavior. Users upgrading from v1.x should thoroughly test their implementations.fixReview the GitHub repository's commit history around v2.0.0 for specific changes. Pay close attention to how `activate()` is configured and any custom formatting options used. Test existing error handling and output for regressions.
affects: >=2.0.0
gotchaEarlier versions (e.g., v1.1.1) introduced `activate_by_import` which could lead to global activation simply by importing the library. While the current recommendation is explicit `tb_with_vars.activate()`, users might mistakenly rely on or accidentally trigger global activation if `activate_by_import` is still enabled by default or via configuration in their environment.fixAlways explicitly call `tb_with_vars.activate()` when global activation is desired to ensure predictable behavior. If auto-activation is not intended, verify that no configuration or old import patterns are implicitly enabling it. Use `tb_with_vars.deactivate()` when global activation is no longer needed.
affects: All versions, particularly relevant for users migrating from 1.x or configuring for specific environments.
Upgrade
Version history
2.2.1latest on PyPI · released Oct 24, 2025
Audit
Dependencies
No dependency data recorded yet.