stackprinter
Debug-friendly stack traces, with variable values and semantic highlighting
What it is and what it does
stackprinter is a Python debugging utility that intercepts exceptions and prints them with significantly more context than the standard traceback. Instead of showing only the line that failed, it displays surrounding source code, the values of all variables visible at each frame, and how each function was called—answering the questions you'd normally ask an interactive debugger without requiring one.
It works in three modes: as a global exception hook (replacing the default crash message), called selectively in except blocks, or integrated with Python's logging module. Output is plain text by default (suitable for log files) but supports color modes for terminal use. Configuration options let you control verbosity, hide sensitive variables, truncate large values, and suppress output from specific code paths.
Use it for:
- Debugging production errors where only log files are available, not an interactive debugger.
- Logging exceptions with full context in long-running services or batch jobs.
- Replacing the default REPL crash message with more informative output via sitecustomize.py.
- Inspecting the current call stack and variable state at any point in code, not just on exception.
- Examining another thread's stack during concurrent debugging.
- Integrating enhanced tracebacks into a custom logging formatter for structured error reporting.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Replaces Python's default exception traceback with an enhanced version that shows surrounding code context and the values of nearby variables at each stack frame.
Yes. Zero dependencies, permissive license, active maintenance, and no known vulnerabilities. Install it if you spend time debugging Python code or need better error context in production logs—it's a low-risk, high-value addition to any Python project.
Install
stackprinter on PyPI
pip
pip install stackprinteruv
uv add stackprinterpoetry
poetry add stackprinterInstalling stackprinter
Before you install
Low friction—pure Python wheel with no runtime dependencies. Actively maintained with recent commits and a solid user base.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects.
Quickstart
pip install stackprinter
import stackprinter
stackprinter.set_excepthook(style='darkbg2')
# or in an except block:
try:
risky_call()
except:
stackprinter.show()
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.4) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 119 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 444,664/month — #6,621 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: stackprinter-0.2.13-py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
devtoolsProvides a `debug()` function that prints…
permissive · top 5,000 on PyPI
stack-dataExtracts and displays stack frame and traceback…
permissive · top 1,000 on PyPI
traceriteFormats Python exceptions and tracebacks into…
permissive · top 5,000 on PyPI
colored-tracebackAutomatically colors Python exception…
permissive · top 5,000 on PyPI
crashtestCrashtest provides utilities to catch, inspect,…
permissive · top 1,000 on PyPI
tracebackturbo3A drop-in replacement for Python's traceback…
permissive · top 15,000 on PyPI
tblibSerializes exceptions and tracebacks to pickle…
permissive · top 1,000 on PyPI
pretty-errorsReformats Python exception tracebacks with…
permissive · top 15,000 on PyPI
exceptiongroupProvides exception group classes and utilities…
permissive · top 1,000 on PyPI
cli-exit-toolsHandles proper exit procedures for CLI…
permissive · top 5,000 on PyPI