Skip to main content

debugonce

Effortlessly capture and reproduce bugs in your Python code.

PyPI Downloads PyPI License: MIT Python Versions


🔍 Overview

debugonce is a Python utility that makes debugging easier by capturing function calls, inputs, and runtime context. With a simple decorator, you can store a snapshot of any function execution and replay it later for consistent bug reproduction.


✨ Features

  • 🧠 Automatically captures function arguments, environment variables, working directory, Python version, stack trace, file access, and HTTP requests.
  • 📁 Saves session data to .debugonce/ as readable JSON files.
  • 🧪 CLI commands to inspect, replay, export, list, or clean captured sessions.
  • 🧵 Reproduce bugs consistently with auto-generated _replay.py scripts that include the full function implementation and do not require the @debugonce decorator at replay time.
  • ✅ Robust tracking even in the presence of test-time mocks (file and HTTP access are always captured).
  • 🔒 Logging is isolated to .debugonce/debugonce.log and never corrupts session files.
  • 🧩 Arguments are faithfully serialized (strings quoted, numbers as-is) for accurate replay.
  • ✅ Minimal setup — just decorate and debug!

📦 Installation

pip install debugonce

🚀 Basic Usage

1. Decorate Your Function

To capture the state of a function, simply decorate it with @debugonce:

from debugonce_packages import debugonce

@debugonce
def divide(x, y):
    return x / y

divide(4, 2)
divide(10, 0)  # This will raise an error and trigger capture

2. Check the Captured Session

.debugonce/
├── session_<timestamp>.json
├── session_<timestamp>_replay.py
├── debugonce.log

🛠️ CLI Commands

🔎 List All Sessions

debugonce list

🧾 Inspect a Session

debugonce inspect .debugonce/session_<timestamp>.json

📤 Export a Session

Generates a _replay.py file to recreate the captured call, including the function implementation and correct argument quoting:

debugonce export .debugonce/session_<timestamp>.json

▶️ Replay the Session

Executes the _replay.py to reproduce the same error with the same scenario. Exception output is printed to stderr for CLI visibility.

debugonce replay .debugonce/session_<timestamp>.json

🧹 Clean All Sessions

debugonce clean

📁 What’s Captured?

  • ✅ Function name and arguments (with correct types/quoting)
  • ✅ HTTP Requests
  • ✅ File access (read/write)
  • ✅ Python version
  • ✅ Current working directory
  • ✅ Environment variables
  • ✅ Stack trace (if an error occurred)
  • ✅ Timestamp

🔧 Advanced Example

from debugonce_packages import debugonce

@debugonce
def fetch_and_save_post(post_id, filename):
    """Fetch a post from an API and save its title to a file."""
    url = f"https://jsonplaceholder.typicode.com/posts/{post_id}"
    response = requests.get(url)
    data = response.json()
    title = data["title"]
    with open(filename, "w") as f:
        f.write(title)
    return title

fetch_and_save_post(1, "post_title.txt")

Then run:

debugonce export .debugonce/session_<timestamp>.json
debugonce replay .debugonce/session_<timestamp>_replay.py

📂 Project Structure

project/
├── your_code.py        
└── .debugonce/
    ├── session_<timestamp>.json    # Generated by `debugonce export`
    ├── session_<timestamp>_replay.py
    ├── debugonce.log

🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. If you'd like to contribute code:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes, including tests if applicable.
  4. Ensure all tests pass.
  5. Submit a pull request.

or


📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.



🏷️ Keywords

debugonce · python debugging · function replay · bug capture · debug decorator · debug CLI · reproducible debugging · python trace logger, debugging, production logging,

Metadata

Release files for debugonce 0.6.3

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

Built distribution (wheel)

Table of built distributions (wheels) for debugonce 0.6.3
File Interpreter ABI Platform
debugonce-0.6.3-py3-none-any.whl Python 3 none any Details

Release files / debugonce-0.6.3-py3-none-any.whl

Download URL debugonce-0.6.3-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62f85a0b88510a85cd9e78d3f61e0c0552c97b4890bd2256bed6c4a6e92dc8db
BLAKE2b-256 checksum
How to use checksums
efc39ccfc343dc9bdcbcd545885a5dda198f62ebb8580e704053831d1754f745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.6.3 This release

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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