Stack Data
raw JSON → 0.6.3 verified Tue May 12 auth: no python install: verified quickstart: verified
stack-data is a Python library designed to extract detailed information from stack frames and tracebacks, offering more useful and customizable displays than Python's default tracebacks. It's currently at version 0.6.3 and is actively maintained, powering features in tools like IPython and futurecoder.
pip install stack-data Common errors
error ModuleNotFoundError: No module named 'stack_data' ↓
cause The 'stack-data' package is not installed in the current Python environment, or there's a typo in the import statement (it's 'stack-data' for pip, 'stack_data' for import).
fix
Ensure the package is installed using
pip install stack-data. error AttributeError: 'Line' object has no attribute 'text' ↓
cause The user attempted to access a non-existent 'text' attribute on a `stack_data.Line` object; the textual content of a line is accessed via its `render()` method.
fix
Use
line.render() to get the string representation of the code line. error ERROR: Package 'stack-data' requires a different Python version: '>=3.8' but you have '3.7.x' ↓
cause The current Python environment's version is older than the minimum required by `stack-data` (version 0.6.3 requires Python 3.8 or newer).
fix
Upgrade your Python installation to version 3.8 or newer, or switch to an environment with a compatible Python version.
error TypeError: FrameInfo expected a frame, got <class 'str'> ↓
cause The `stack_data.FrameInfo` constructor was called with an argument that is not a Python `frame` object, which is required for it to extract frame data.
fix
Pass an actual frame object (e.g., obtained from
sys._getframe() or an exception traceback) to stack_data.FrameInfo. Warnings
gotcha When inspecting recursive functions or deeply nested calls, `stack_data`, similar to Python's built-in traceback, automatically avoids showing all identical repeated frames. It instead provides a `RepeatedFrames` object. If you need to see every single frame, you must explicitly pass `collapse_repeated_frames=False` to `FrameInfo` (not to `Options`). ↓
fix Pass `collapse_repeated_frames=False` to `stack_data.FrameInfo` when initializing, e.g., `stack_data.FrameInfo(frame, collapse_repeated_frames=False)`.
gotcha When rendering lines that include markers (e.g., for highlighting or inserting HTML), ensure you use `line.render(markers, escape_html=True)` if you are inserting HTML. This will correctly escape special HTML characters in the Python source code to prevent malformed output, while still allowing your markers to be interpreted as HTML. ↓
fix Use `line.render(markers, escape_html=True)` when preparing output for HTML display, especially if markers themselves contain unescaped HTML.
gotcha The basic `line.render()` method strips common leading indentation. If preserving exact original indentation (including common leading whitespace) is critical for your display logic, be aware that `line.render()` modifies it. More advanced control over rendering and ranges is available via `line.token_ranges` or `line.range_from_node`. ↓
fix For custom indentation control, consider iterating through `line.token_ranges` and reconstructing the line, or use `line.range_from_node(node, data)` for more granular control over specific parts of the line.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.12s 18.5M
3.10 alpine (musl) - - 0.10s 18.5M
3.10 slim (glibc) wheel 1.6s 0.10s 19M
3.10 slim (glibc) - - 0.11s 19M
3.11 alpine (musl) wheel - 0.16s 20.4M
3.11 alpine (musl) - - 0.18s 20.4M
3.11 slim (glibc) wheel 1.7s 0.14s 21M
3.11 slim (glibc) - - 0.13s 21M
3.12 alpine (musl) wheel - 0.14s 12.3M
3.12 alpine (musl) - - 0.14s 12.3M
3.12 slim (glibc) wheel 1.5s 0.14s 13M
3.12 slim (glibc) - - 0.14s 13M
3.13 alpine (musl) wheel - 0.13s 12.0M
3.13 alpine (musl) - - 0.13s 11.9M
3.13 slim (glibc) wheel 1.6s 0.13s 12M
3.13 slim (glibc) - - 0.13s 12M
3.9 alpine (musl) wheel - 0.07s 17.9M
3.9 alpine (musl) - - 0.08s 17.9M
3.9 slim (glibc) wheel 1.9s 0.06s 18M
3.9 slim (glibc) - - 0.06s 18M
Imports
- FrameInfo
from stack_data import FrameInfo - Options
from stack_data import Options - Line
from stack_data import Line
Quickstart verified last tested: 2026-04-23
import inspect
import stack_data
def foo():
result = []
for i in range(2):
row = []
result.append(row)
print_stack()
for j in range(2):
row.append(i * j)
return result
def print_stack():
frame = inspect.currentframe().f_back
frame_info = stack_data.FrameInfo(frame)
print(f"{frame_info.code.co_name} at line {frame_info.lineno}")
print("-----------")
for line in frame_info.lines:
print(f"{'-->' if line.is_current else ' '} {line.lineno:4} | {line.render()}")
foo()