Skip to main content

Traceback Serializer Project (offline-debug)

PyPI version Tests Coverage Ruff Ty checked

Overview

A Python package for high-fidelity serialization and deserialization of exceptions and their complete tracebacks. Unlike other solutions, offline-debug reconstructs actual types.FrameType objects using the Python C API, ensuring that re-raised exceptions look and feel genuine to debuggers and introspection tools.

Core Functions

  • save_traceback(exc: BaseException, file: Path | BytesIO, proxy_types=DEFAULT_PROXY_TYPES, *, max_value_bytes=None): Serializes an exception, its traceback, and all picklable local/global variables to a binary file or buffer. proxy_types names classes whose instances must never be touched (see Object proxies). max_value_bytes caps the pickled size of each variable; larger ones are stored as a placeholder with a shortened repr, so a single large object cannot turn the dump into gigabytes.
  • load_traceback(file: Path | BytesIO) -> Never: Loads the serialized state, reconstructs the exception and its full traceback chain (including __cause__ and __context__), and raises it.
  • parse_traceback(file: Path | BytesIO) -> ExceptionData: Loads the serialized data and returns an ExceptionData object. This allows for inspecting the exception, stack frames, and variables without reconstructing the full traceback or raising the exception.

Usage Example

To get started, install with:
pip install offline-debug or uv add offline-debug

from pathlib import Path
from offline_debug import save_traceback, load_traceback, parse_traceback

# --- Saving an exception ---
try:
    some_complex_operation()
except Exception as e:
    save_traceback(e, Path("crash_report.dump"))

# --- Option 1: Re-raise the exception for debugging ---
# This will look like the original crash in your debugger
load_traceback(Path("crash_report.dump"))

# --- Option 2: Inspect data without raising ---
data = parse_traceback(Path("crash_report.dump"))
print(f"Number of frames: {len(data.tb_frames)}")
for frame in data.tb_frames:
    print(f"File: {frame.code.filename}, Line: {frame.lineno}")

Exception Group Support

offline-debug has full support for ExceptionGroup (Python 3.11+). When you parse a saved ExceptionGroup, you can access its nested exceptions:

from offline_debug import parse_traceback, ExceptionGroupData

data = parse_traceback(Path("exception_group.dump"))

if isinstance(data, ExceptionGroupData):
    print(f"Group contains {len(data.exceptions)} sub-exceptions")
    for sub_exc_data in data.exceptions:
        # Each sub_exc_data is itself an ExceptionData object
        print(f"Sub-exception frames: {len(sub_exc_data.tb_frames)}")

Object proxies

An object proxy such as an rpyc netref turns every instance operation - attribute reads, repr, isinstance (through __class__), pickling (through __reduce_ex__) - into a remote call that blocks for the peer's full timeout once the connection breaks, and a dead peer is often why the code crashed. So save_traceback recognises proxies from their type alone and writes a placeholder like <proxy rpyc.core.netref.SaharaClient at 0x7f...> without touching the instance:

save_traceback(e, dump_file, proxy_types=(*DEFAULT_PROXY_TYPES, MyProxyBase))

An entry is a class or a fully-qualified class name such as "rpyc.core.netref.BaseNetref", which names a proxy family without importing its package; both forms match subclasses, since only type(value).__mro__ is consulted. DEFAULT_PROXY_TYPES covers rpyc netrefs out of the box. Proxies are replaced wherever they appear: frame variables, items nested in containers, and an exception's args or attributes.

An unregistered proxy is still slow to save, but can no longer lose the dump: a placeholder falls back to the bare object repr when repr or str raises.

Technical Implementation

  • True Frame Reconstruction: Uses ctypes to call PyFrame_New from the Python C API. This creates real frame objects which are required for a valid types.TracebackType.
  • Python 3.13 Compatibility: Leverages PEP 667 features where f_locals is a write-through proxy, allowing for accurate local variable restoration.
  • Support python 3.12 as well
  • Resilient Serialization:
    • pickle is used for exceptions and variables.
    • Only the code metadata a frame needs (file name, name, qualified name, first line) is stored, so dumps carry nothing specific to the interpreter that wrote them.
    • Non-picklable items are gracefully handled by storing their repr.
    • Modules are not picklable, so the attributes a frame reads from a module global (e.g. constants.TIMEOUT) are snapshotted into a namespace under the module's name.
    • A value whose class cannot be imported where the dump is loaded (a class that moved between Python versions, or one from the crashing script's __main__) loads as a stand-in carrying its pickled arguments and attributes instead of failing the whole load.

Development & Tooling

  • Package Manager: uv
  • Minimum Python: 3.12
  • Testing: pytest
  • Commands:
    • Add dependencies: uv add <package>
    • Run tests: uv run pytest

Metadata

Release files for offline-debug 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for offline-debug 0.4.0
File Size Uploaded Provenance Actions
offline_debug-0.4.0.tar.gz 18.5 kB With provenance Details for offline_debug-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for offline-debug 0.4.0
File Interpreter ABI Platform Actions
offline_debug-0.4.0-py3-none-any.whl Python 3 none any Details for offline_debug-0.4.0-py3-none-any.whl

Total release size: 40.0 kB

Release files / offline_debug-0.4.0.tar.gz

Download URL offline_debug-0.4.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
697e023cb6c925eb6e72b0f52004219c68cc511c3a74dda5b7f63c285b35b35c
BLAKE2b-256 checksum
How to use checksums
1b237e44f2763e6325bfb41a13d162233c51a8c677f356e2f0a64cbdd3292ac8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / offline_debug-0.4.0-py3-none-any.whl

Download URL offline_debug-0.4.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d904f7956179aa72db2bae123c87df0c900fed3fcec47fced4540796f7459e1f
BLAKE2b-256 checksum
How to use checksums
4043214d64b4dbb56c3e37f0ae4a4b86f57d872bdb1629df600f045b866dd9ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for offline-debug 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for offline_debug-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page