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): Serializes an exception, its traceback, and all picklable local/global variables to a binary file or buffer.
  • 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.co_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)}")

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.
    • marshal is used for code objects.
    • Non-picklable items are gracefully handled by storing their repr.

Development & Tooling

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

offline_debug-0.3.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

offline_debug-0.3.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file offline_debug-0.3.1.tar.gz.

File metadata

  • Download URL: offline_debug-0.3.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for offline_debug-0.3.1.tar.gz
Algorithm Hash digest
SHA256 22fae304d01ffcee595bd09570fa706a55eb61b84efcd6c0f7338fba329b0acf
MD5 96eeb82523ccb1dd607e48cbb4cff8c7
BLAKE2b-256 4900b2df58f24f803423d63cce40bc18323906208c23261986c07345704802b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for offline_debug-0.3.1.tar.gz:

Publisher: ci.yml on INTODAN/offline-debug

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file offline_debug-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: offline_debug-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for offline_debug-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 39d3d5a4e5c24cbae0dd9e67fdb6af02695a3b26c8ab5b666560e7ce0311f4f0
MD5 7aae411c84af92460150e5a8b3bddea5
BLAKE2b-256 ceacc3a61a3058c34ce4b159e8879f245d5e448492d2e6fcf936387ea928551b

See more details on using hashes here.

Provenance

The following attestation bundles were made for offline_debug-0.3.1-py3-none-any.whl:

Publisher: ci.yml on INTODAN/offline-debug

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page