{"id":583,"library":"stack-data","title":"Stack Data","description":"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.","status":"active","version":"0.6.3","language":"python","source_language":"en","source_url":"https://github.com/alexmojaki/stack_data","tags":["debugging","introspection","tracebacks","stack frames","developer tools"],"install":[{"cmd":"pip install stack-data","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used to get the currently executing AST node of a frame and other information.","package":"executing"},{"reason":"Used to annotate AST trees with source code positions.","package":"asttokens"},{"reason":"Used for safely evaluating AST nodes without side effects to identify 'interesting' expressions.","package":"pure_eval"}],"imports":[{"symbol":"FrameInfo","correct":"from stack_data import FrameInfo"},{"symbol":"Options","correct":"from stack_data import Options"},{"symbol":"Line","correct":"from stack_data import Line"}],"quickstart":{"code":"import inspect\nimport stack_data\n\ndef foo():\n    result = []\n    for i in range(2):\n        row = []\n        result.append(row)\n        print_stack()\n        for j in range(2):\n            row.append(i * j)\n    return result\n\ndef print_stack():\n    frame = inspect.currentframe().f_back\n    frame_info = stack_data.FrameInfo(frame)\n    print(f\"{frame_info.code.co_name} at line {frame_info.lineno}\")\n    print(\"-----------\")\n    for line in frame_info.lines:\n        print(f\"{'-->' if line.is_current else ' '} {line.lineno:4} | {line.render()}\")\n\nfoo()","lang":"python","description":"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."},"warnings":[{"fix":"Pass `collapse_repeated_frames=False` to `stack_data.FrameInfo` when initializing, e.g., `stack_data.FrameInfo(frame, collapse_repeated_frames=False)`.","message":"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`).","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use `line.render(markers, escape_html=True)` when preparing output for HTML display, especially if markers themselves contain unescaped HTML.","message":"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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"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`.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-12T16:20:36.492Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure the package is installed using `pip install 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).","error":"ModuleNotFoundError: No module named 'stack_data'"},{"fix":"Use `line.render()` to get the string representation of the code line.","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.","error":"AttributeError: 'Line' object has no attribute 'text'"},{"fix":"Upgrade your Python installation to version 3.8 or newer, or switch to an environment with a compatible Python version.","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).","error":"ERROR: Package 'stack-data' requires a different Python version: '>=3.8' but you have '3.7.x'"},{"fix":"Pass an actual frame object (e.g., obtained from `sys._getframe()` or an exception traceback) to `stack_data.FrameInfo`.","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.","error":"TypeError: FrameInfo expected a frame, got <class 'str'>"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"0.6.3","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":3.6,"disk_size":"18.5M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":3.6,"disk_size":"18.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.1,"mem_mb":3.7,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.11,"mem_mb":3.7,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":4.2,"disk_size":"20.4M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.18,"mem_mb":4.2,"disk_size":"20.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0.14,"mem_mb":4.2,"disk_size":"21M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":4.2,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":4,"disk_size":"12.3M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":4,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.14,"mem_mb":4,"disk_size":"13M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":4,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":4,"disk_size":"12.0M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":4,"disk_size":"11.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.13,"mem_mb":3.8,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":3.8,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":3.6,"disk_size":"17.9M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":3.6,"disk_size":"17.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.9,"import_time_s":0.06,"mem_mb":3.6,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":3.6,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}