Debug exceptions offline by saving them to a dump and raising them at a later point.
Project description
Traceback Serializer Project (offline-debug)
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 anExceptionDataobject. 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
ctypesto callPyFrame_Newfrom the Python C API. This creates realframeobjects which are required for a validtypes.TracebackType. - Python 3.13 Compatibility: Leverages PEP 667 features where
f_localsis a write-through proxy, allowing for accurate local variable restoration. - Support python 3.12 as well
- Robust Serialization:
pickleis used for exceptions and variables.marshalis 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
- Add dependencies:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file offline_debug-0.3.0.tar.gz.
File metadata
- Download URL: offline_debug-0.3.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d17b9e0eb4112b4629a202d226ccca86886003353e4568432b46818ca58b2d7
|
|
| MD5 |
8bd57d142b256e126193e2c68a157f4e
|
|
| BLAKE2b-256 |
c0c6b02f648a20d9c03a7f6bbbbbde784456e24de79853c2f4847826ae98f45c
|
Provenance
The following attestation bundles were made for offline_debug-0.3.0.tar.gz:
Publisher:
ci.yml on INTODAN/offline-debug
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
offline_debug-0.3.0.tar.gz -
Subject digest:
5d17b9e0eb4112b4629a202d226ccca86886003353e4568432b46818ca58b2d7 - Sigstore transparency entry: 1731804720
- Sigstore integration time:
-
Permalink:
INTODAN/offline-debug@f8ff88e451e39125d6eb044af4bb9ecb29e5b76a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/INTODAN
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f8ff88e451e39125d6eb044af4bb9ecb29e5b76a -
Trigger Event:
push
-
Statement type:
File details
Details for the file offline_debug-0.3.0-py3-none-any.whl.
File metadata
- Download URL: offline_debug-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51d2d13ce60d0beb02fa47b5b7f647b08ba8d351ffc6ed246c4f8fd43eeb95a5
|
|
| MD5 |
4821c24d9024f6f564cf2dfd4e0602db
|
|
| BLAKE2b-256 |
44e85de8be9e95753126677d5ca3fd60508d5916aa1e898971f2d0b9a75ce1f5
|
Provenance
The following attestation bundles were made for offline_debug-0.3.0-py3-none-any.whl:
Publisher:
ci.yml on INTODAN/offline-debug
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
offline_debug-0.3.0-py3-none-any.whl -
Subject digest:
51d2d13ce60d0beb02fa47b5b7f647b08ba8d351ffc6ed246c4f8fd43eeb95a5 - Sigstore transparency entry: 1731804996
- Sigstore integration time:
-
Permalink:
INTODAN/offline-debug@f8ff88e451e39125d6eb044af4bb9ecb29e5b76a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/INTODAN
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f8ff88e451e39125d6eb044af4bb9ecb29e5b76a -
Trigger Event:
push
-
Statement type: