Skip to main content

Debugger Decorator

A simple Python decorator for debugging functions.

Installation

pip install debugger-decorator

Usage

from debugger_decorator import show_information

@show_information()
def my_function(a, b):
    return a + b

my_function(1, 2)

This will print information about the function call, its arguments, return value, and execution time.

Parameters

  • debug (bool, default=True): Enable or disable debugging output.
  • color_scheme (dict, optional): Custom color scheme for terminal output.
  • track_vars (list or str, optional): Variables to track for changes during execution.
  • log_file (str, optional): File path to write output instead of stdout (plain text, no colors).
  • deep_track (bool, default=False): Use deep copying for variable tracking to detect in-place changes.

Variable Tracking

Track changes to specific variables during function execution:

@show_information(track_vars=['result'])
def calculate(x, y):
    result = x + y
    result *= 2
    return result

calculate(3, 4)

For deep tracking of in-place modifications:

@show_information(track_vars=['data'], deep_track=True)
def modify_list(data):
    data.append(5)  # Detected with deep_track
    return data

Output Redirection

Redirect debug output to a file:

@show_information(log_file='debug.log')
def my_function(a, b):
    return a + b

my_function(1, 2)  # Output to debug.log

Customizing Colors

You can customize the color scheme for better accessibility or personal preference:

from debugger_decorator import show_information
from colorama import Fore, Style, Back

# High contrast color scheme
high_contrast_colors = {
    'header': Style.BRIGHT + Fore.WHITE,
    'params': Fore.CYAN,
    'running': Style.BRIGHT + Fore.YELLOW,
    'return': Back.GREEN + Style.BRIGHT + Fore.BLACK,
    'time': Style.BRIGHT + Fore.GREEN,
    'error': Style.BRIGHT + Fore.RED,
    'dashes': Style.BRIGHT + Fore.WHITE,
    'error_dashes': Style.BRIGHT + Fore.RED,
    'tracking': Style.BRIGHT + Fore.MAGENTA,
}

@show_information(color_scheme=high_contrast_colors)
def my_function(a, b):
    return a + b

my_function(1, 2)

Available color keys:

  • header: Function name and caller info
  • params: Parameter names and values
  • running: "Running . . ." message
  • return: Return value display
  • time: Execution time
  • error: Error messages
  • dashes: Separator lines
  • error_dashes: Error separator lines
  • tracking: Variable change messages

Uses Colorama styles (DIM, NORMAL, BRIGHT) and colors (Fore., Back., Style.*).

Error Handling

The decorator catches and displays exceptions with colors:

@show_information()
def failing_function():
    raise ValueError("Something went wrong")

failing_function()  # Shows error message and re-raises

Testing

Run the test suite:

python -m pytest tests/ -v

Performance Notes

  • Variable tracking uses sys.settrace, which may slow down execution for large functions.
  • A warning is printed if execution takes more than 1 second.
  • For production, set debug=False to disable output.

Development

  • Variable tracking uses sys.settrace, which may slow down execution for large functions.
  • A warning is printed if execution takes more than 1 second.
  • For production, set debug=False to disable output.

Building the Package

To build the package for distribution:

pip install build
python -m build

This creates dist/debugger_decorator-<version>.tar.gz and dist/debugger_decorator-<version>-py3-none-any.whl.

Publishing to PyPI

  1. Install Twine:

    pip install twine
    
  2. Upload to Test PyPI (recommended first):

    twine upload --repository testpypi dist/*
    
  3. Upload to Production PyPI:

    twine upload dist/*
    

You'll need a PyPI account and API token. Set it up at pypi.org and use __token__ as username with your token as password.

Metadata

Release files for debugger-decorator 0.1.4

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

Source distribution (sdist)

Source distribution for debugger-decorator 0.1.4
File Size Uploaded
debugger_decorator-0.1.4.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for debugger-decorator 0.1.4
File Interpreter ABI Platform
debugger_decorator-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / debugger_decorator-0.1.4.tar.gz

Download URL debugger_decorator-0.1.4.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b92fd4ace86f3d8517ca5a57d032d224a81eedcb1b9369878a0f2c707e1dc455
BLAKE2b-256 checksum
How to use checksums
7f3fc5a3c0225ccb72cd4d230570582343d1ba216b6ef992afedcbbb06bf793c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / debugger_decorator-0.1.4-py3-none-any.whl

Download URL debugger_decorator-0.1.4-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3c5ffc14083f431482ed181de9392ee0406728105a4c735c9ab2fee7c2c4474
BLAKE2b-256 checksum
How to use checksums
7d216b07db6d0722f3259c94a26322fce284840eead4118740406dde89e2cc35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

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