Registry / testing / traceback-with-variables

traceback-with-variables

JSON →
library2.2.1pypypi✓ verified 84d ago

traceback-with-variables is a Python library that enhances standard tracebacks by adding local variable contexts for each frame in a stacktrace. It helps in debugging by showing variable values at the point of an exception, offering features like colorful output, configurable formatting, and integration with Jupyter/IPython. Currently at version 2.2.1, it receives active maintenance with minor releases.

pip install traceback-with-variables
INSTALL
IMPORT
SIG · TRACEBACK-WITH-VAR
T
traceback-with-variables
testingpythonv2.2.1
Install
1.7s avg
Import
65ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.068s · 17.9MB
glibc
py 3.103.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.
fix
If 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.
fix
Use `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.
fix
Review 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.
fix
Always 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.

Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
traceback-with-variables — pip install traceback-with-variables · libregistry