DEV.co
Open-Source Observability · andy-landy

traceback_with_variables

traceback_with_variables is a Python debugging library that automatically captures and displays local variable values when exceptions occur. It eliminates manual logging of exception context by hooking into Python's traceback system to show every variable at each stack frame.

Source: GitHub — github.com/andy-landy/traceback_with_variables
704
GitHub stars
31
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryandy-landy/traceback_with_variables
Ownerandy-landy
Primary languagePython
LicenseMIT — OSI-approved
Stars704
Forks31
Open issues9
Latest releasev2.2.0 (2025-02-21)
Last updated2025-10-24
Sourcehttps://github.com/andy-landy/traceback_with_variables

What traceback_with_variables is

The library intercepts Python's exception handling via traceback hooks or decorators/context managers to iterate through stack frames and extract local variables. It provides customizable formatting, color output, and works across Jupyter, standard scripts, and CLI invocation without code modification.

Quickstart

Get the traceback_with_variables source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/andy-landy/traceback_with_variables.gitcd traceback_with_variables# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Development debugging of complex call stacks

Quickly identify state at each frame during development without pre-writing exception handlers or logging statements. Particularly useful for multi-layer stack traces where variable inspection saves iteration time.

Interactive and notebook environments

Works natively in Jupyter and IPython notebooks where re-running code to reproduce errors is expensive. Provides rich, colorized variable context immediately after an exception.

CI/CD and unattended script debugging

Invoke scripts via CLI wrapper (`traceback-with-variables script.py`) to capture full variable state on remote or headless environments without modifying the target script.

Implementation considerations

  • Import `activate_by_import` early in entry point for global activation, or use `@prints_exc` decorator or `with printing_exc()` context for granular scope control.
  • Customize `fmt` object (max_value_str_len, skip_files_except, custom_var_printers) to avoid dumping excessive data or sensitive variables in your environment.
  • For logger integration, wrap logger with `LoggerAsFile()` adapter; ensure log rotation and size limits are configured, as large tracebacks can bloat log volume.
  • Test color output on target platforms (Windows Console ANSI support has quirks); library reports cross-platform support but validate in your deployment environment.
  • Consider exception filtering strategy early: decide whether to apply library globally or only to specific functions/modules to manage output verbosity and overhead.

When to avoid it — and what to weigh

  • Production systems with strict performance requirements — Capturing full local scope for every frame in large/nested stacks incurs overhead. README explicitly suggests 'small-scale production' only; not recommended for high-throughput services.
  • Large or sensitive object serialization concerns — The library dumps all local variables to output/logs including potentially large data structures or secrets. Requires careful configuration of filters and max string lengths to avoid exposing sensitive data.
  • Strict, pre-existing exception-handling architecture — If your codebase has a custom exception context system or proprietary traceback processing, integrating this library may conflict or duplicate effort. Legacy systems with custom metaclass hooks warrant review.
  • Real-time systems with strict latency SLAs — Frame introspection and string formatting can introduce unpredictable latency spikes. Not suitable for hard real-time or ultra-low-latency constraints.

License & commercial use

Licensed under MIT (MIT License), a permissive OSI-approved license. Grants rights to use, modify, distribute, and sublicense, subject only to preservation of copyright and license notices.

MIT is a permissive open-source license; commercial use is explicitly permitted. However, this is a debugging tool; ensure your commercial product's exception handling and variable logging comply with your data protection and privacy policies, especially regarding customer data exposure in logs.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Library dumps all local variables to output/logs by default. In production, this can leak secrets (passwords, tokens, API keys) if present in scope. Mitigation: use `custom_var_printers` or `skip_files_except` to filter sensitive values, enforce max string length, and audit what reaches logs. No security audit or CVE history evident in provided data.

Alternatives to consider

ipdb / pdb (Python built-in debugger)

Interactive debugging with full REPL access; better for development but requires manual breakpoints and human presence. Not suitable for unattended/production scenarios.

Better Exceptions (better_exceptions / rich.traceback)

Provide enhanced traceback formatting and syntax highlighting but do not capture live variable state. Lighter-weight than traceback_with_variables but less diagnostic power.

Custom exception context logging (manual try-except + logging)

Full control and minimal overhead; widely used in production systems. Requires more boilerplate and discipline to maintain comprehensive logging across all error paths.

Software development agency

Build on traceback_with_variables with DEV.co software developers

Reduce exception-hunting time by automatically capturing variable state at each stack frame. Install traceback_with_variables and integrate it into your development and staging workflows.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

traceback_with_variables FAQ

Does it work in production?
Library docs say 'try for debug and keep for small-scale production.' Overhead from frame introspection and variable serialization makes it risky for high-throughput or latency-sensitive systems. Recommended for development, staging, and light production use with careful filtering.
Will it expose secrets or sensitive data?
Yes, by default it dumps all local variables. Mitigate by configuring `custom_var_printers` to redact, using `skip_files_except` to exclude certain modules, or setting `max_value_str_len` to limit output. Audit your exception paths to ensure no secrets enter scope.
Can I use it with async or threaded code?
Library provides no explicit async/threading notes. Frame-based introspection should work with async code (frames exist in both), but concurrency-related variable visibility and performance under contention are untested per provided data. Requires verification.
How does it compare to full debuggers like PyCharm's debugger?
This library is post-hoc: it captures state after an exception occurs. Full debuggers offer step-through, watches, and REPL during execution. traceback_with_variables is lighter-weight and requires no IDE; useful for remote or headless environments where full debuggers are unavailable.

Software developers & web developers for hire

From first prototype to production, DEV.co delivers software development services around tools like traceback_with_variables. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source observability and beyond.

Streamline Python Debugging

Reduce exception-hunting time by automatically capturing variable state at each stack frame. Install traceback_with_variables and integrate it into your development and staging workflows.