Registry / testing / stack-data

stack-data

JSON →
library0.6.3pypypi✓ verified 35d ago

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.

testingobservability
Install & Compatibility
Where this runs
tested against v0.6.3 · 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.925 runs
installs and imports cleanly · install 0.0s · import 0.123s · 18.5MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.7s · import 0.114s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from stack_data import FrameInfo
from stack_data import Options
from stack_data import Line

This example demonstrates basic usage by creating a FrameInfo object from the current frame and then iterating through its lines to print the source code, highlighting the current line.

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()
Debug
Known footguns
gotchaWhen 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`).
gotchaWhen 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.
gotchaThe 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`.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
38 hits · last 30 days
bingbot
5
gptbot
4
ahrefsbot
4
amazonbot
4
bytedance
3
claudebot
3
petalbot
1
Resources