# API Reference

Technical reference for public modules, CLI commands, and internal core subsystems.

## Public Interface

Public modules and entrypoints designed for direct consumption:

### Package Root

## debug\_dojo

Opinionated Python debugger and runner powered by `dpdb` and Rich.

Importing `debug_dojo.install` injects debugging tools into Python's builtins:

```python
import debug_dojo.install

b()
```

This configures `dpdb` as the active debugger, installs debugging helpers (`b()`, `p()`, `i()`, `c()`), and triggers a breakpoint.

You can also invoke `set_trace()`, `post_mortem()`, or `pm()` directly:

```python
import debug_dojo

debug_dojo.set_trace()
```

Or run target scripts, modules, or commands directly from the CLI:

```console
$ uvx debug-dojo target_script.py value_1
```

Modules:

| Name | Description |
| --- | --- |
| `cli` | Command-line interface for running targets with the `dpdb` debugger. |
| `install` | Install opinionated debugging tools into the current Python runtime. |

Functions:

| Name | Description |
| --- | --- |
| `pm` | Enter `dpdb` post-mortem debugging on the last unhandled exception. |
| `post_mortem` | Enter post-mortem debugging on the given or active exception traceback. |
| `set_trace` | Enter the internal DPDB debugger at the given or calling stack frame. |

### pm

```python
pm() -> None
```

Enter `dpdb` post-mortem debugging on the last unhandled exception.

### post\_mortem

```python
post_mortem(tb: TracebackType | None = None) -> None
```

Enter post-mortem debugging on the given or active exception traceback.

Args: tb (TracebackType | None): Traceback to inspect (defaults to active exc\_info).

### set\_trace

```python
set_trace(frame: FrameType | None = None) -> None
```

Enter the internal DPDB debugger at the given or calling stack frame.

Args: frame (FrameType | None): Target stack frame. Defaults to the caller's frame.

### In-Code Installer

## debug\_dojo.install

Install opinionated debugging tools into the current Python runtime.

### Command Line Interface

## debug\_dojo.cli

Command-line interface for running targets with the `dpdb` debugger.

Classes:

| Name | Description |
| --- | --- |
| `CliArgs` | Parsed command-line arguments for Dojo. |
| `CliResult` | Result of running a CLI invocation in a captured buffer. |
| `CliRunner` | Runner for invoking `dojo` CLI commands in test and automation environments. |

Functions:

| Name | Description |
| --- | --- |
| `get_version` | Return the package version string. |
| `render_help` | Render the formatted CLI help screen using Rich panels. |
| `parse_cli_args` | Parse raw CLI argument strings into structured `CliArgs`. |
| `cli` | Execute the `dojo` command-line interface. |
| `main` | Entry point for the `debug-dojo` and `dojo` CLI commands. |

### CliArgs

```python
CliArgs(
    target: str | None = None,
    target_args: tuple[str, ...] = (),
    breaks: tuple[str, ...] = (),
    show_help: bool = False,
    show_version: bool = False,
    error: str | None = None,
)
```

Parsed command-line arguments for Dojo.

Attributes: target: Target script, module, or executable to debug. target\_args: Command-line arguments forwarded directly to the target. breaks: Initial breakpoint expressions armed before running the target. show\_help: Flag indicating whether the help screen should be displayed. show\_version: Flag indicating whether version info should be displayed. error: Validation error message if argument parsing failed.

### CliResult

```python
CliResult(exit_code: int, output: str)
```

Result of running a CLI invocation in a captured buffer.

Attributes: exit\_code: Exit status code. output: Captured combined standard and error output text.

### CliRunner

```python
CliRunner(env: Mapping[str, str] | None = None)
```

Runner for invoking `dojo` CLI commands in test and automation environments.

Args: env (Mapping\[str, str\] | None): Environment variables to inject during runs.

Methods:

| Name | Description |
| --- | --- |
| `invoke` | Invoke `app` with `args`, capturing combined standard and error output. |

#### invoke

```python
invoke(app: Callable[..., int], args: Sequence[str] | None = None) -> CliResult
```

Invoke `app` with `args`, capturing combined standard and error output.

Args: app (Callable\[..., int\]): The CLI entrypoint function. args (Sequence\[str\] | None): Arguments passed to `app`.

Returns: CliResult: Exit code and captured output.

### get\_version

```python
get_version() -> str
```

Return the package version string.

Returns: str: Installed package version of debug-dojo, or fallback `"0.10.0"`.

### render\_help

```python
render_help(console: Console) -> None
```

Render the formatted CLI help screen using Rich panels.

Args: console (Console): Target Rich console for output rendering.

### parse\_cli\_args

```python
parse_cli_args(args: Sequence[str]) -> CliArgs
```

Parse raw CLI argument strings into structured `CliArgs`.

Args: args (Sequence\[str\]): List of command-line argument strings.

Returns: CliArgs: Structured parsed CLI options and arguments.

### cli

```python
cli(
    args: Sequence[str] | None = None,
    stdout: TextIO | None = None,
    stderr: TextIO | None = None,
) -> int
```

Execute the `dojo` command-line interface.

Args: args (Sequence\[str\] | None): Argument list. Defaults to `sys.argv[1:]`. stdout (TextIO | None): Stream for standard output. Defaults to `sys.stdout`. stderr (TextIO | None): Stream for error output. Defaults to `sys.stderr`.

Returns: int: Exit status code (0 for success, non-zero for errors).

### main

```python
main() -> None
```

Entry point for the `debug-dojo` and `dojo` CLI commands.

## Architecture Dependency Graph

The internal module boundaries and import hierarchy are strictly enforced by [Tach](<https://github.com/gauge-sh/tach>):

```
graph TD
    debug_dojo --> debug_dojo._core
    debug_dojo.__main__ --> debug_dojo.cli
    debug_dojo.cli
    debug_dojo._core
```

## Internal Core Subsystems

Detailed API documentation for internal modules isolated under `debug_dojo._core`:

### Debugger Subsystem

## debug\_dojo.\_core.debugger.debugger

IPython-powered interactive debugger (`DojoPdb`) with Rich enhancements.

Classes:

| Name | Description |
| --- | --- |
| `DojoPdb` | Enhanced IPython debugger with Rich inspection and live frame context. |

### DojoPdb

```python
DojoPdb(
    *args: object,
    pt_session_options: Mapping[str, object] | None = None,
    **kwargs: object,
)
```

Bases: `TerminalPdb`

```

              flowchart TD
              debug_dojo._core.debugger.debugger.DojoPdb[DojoPdb]

              

              click debug_dojo._core.debugger.debugger.DojoPdb href "" "debug_dojo._core.debugger.debugger.DojoPdb"
            
```

Enhanced IPython debugger with Rich inspection and live frame context.

Args: \*args (object): Positional arguments forwarded to `TerminalPdb`. pt\_session\_options (Mapping\[str, object\] | None): Optional `prompt_toolkit` session options. \*\*kwargs (object): Keyword arguments forwarded to `TerminalPdb`.

Methods:

| Name | Description |
| --- | --- |
| `close` | Close prompt\_toolkit event loop and executor resources. |
| `__del__` | Ensure background loop and executor are closed on garbage collection. |
| `message` | Print a message to stdout unless suppressed. |
| `stop_here` | Return whether execution should stop at `frame` during stepping. |
| `user_return` | Handle function return events while skipping redundant or hidden returns. |
| `emptyline` | Repeat `lastcmd` on empty Enter only when it is a safe navigation command. |
| `print_stack_entry` | Print a stack entry with adaptive context lines and live variable banner. |
| `print_stack_trace` | Render a compact Rich call stack table followed by active frame context. |
| `do_context` | Set the number of source context lines shown on frame entry (`context`). |
| `do_break` | Set a breakpoint or render a Rich table of active breakpoints (`b`). |
| `do_continue` | Continue execution until next breakpoint (`c`), or evaluate `c(...)`. |
| `do_display` | Add a watch expression or render a Rich table of watched expressions. |
| `do_whatis` | Display the type, MRO, and signature/size of an expression (`whatis`). |
| `do_psource` | Render syntax-highlighted source code for an object (`psource`). |
| `displayhook` | Render interactive REPL expression results with Rich pretty-printing. |
| `do_p` | Rich-print the value of an expression (`p <expr>`). |
| `do_pp` | Rich pretty-print the expanded value of an expression (`pp <expr>`). |
| `do_pinfo` | Provide detailed information about an object in a Rich panel (`pinfo`). |
| `do_pinfo2` | Provide extra detailed information about an object (`pinfo2`). |
| `do_args` | Display the argument list of the current function in a Rich table (`a`). |
| `do_interact` | Start an interactive IPython shell in the current frame (`interact`). |
| `do_help` | Display the categorized command reference table or help for a command (`h`). |

#### close

```python
close() -> None
```

Close prompt\_toolkit event loop and executor resources.

#### \_\_del\_\_

```python
__del__() -> None
```

Ensure background loop and executor are closed on garbage collection.

#### message

```python
message(msg: str) -> None
```

Print a message to stdout unless suppressed.

Args: msg (str): Message text to output.

#### stop\_here

```python
stop_here(frame: FrameType) -> bool
```

Return whether execution should stop at `frame` during stepping.

Args: frame (FrameType): Candidate stack frame.

Returns: bool: `False` when `frame` is hidden, otherwise superclass result.

#### user\_return

```python
user_return(frame: FrameType, return_value: object) -> None
```

Handle function return events while skipping redundant or hidden returns.

Args: frame (FrameType): Returning stack frame. return\_value (object): Value returned by `frame`.

#### emptyline

```python
emptyline() -> bool
```

Repeat `lastcmd` on empty Enter only when it is a safe navigation command.

Returns: bool: Result of repeating `lastcmd`, or `False` when ignored.

#### print\_stack\_entry

```python
print_stack_entry(
    frame_lineno: tuple[FrameType, int], prompt_prefix: str = "\n-> "
) -> None
```

Print a stack entry with adaptive context lines and live variable banner.

Args: frame\_lineno (tuple\[FrameType, int\]): Target `(frame, lineno)` pair. prompt\_prefix (str): Prefix string forwarded to superclass.

#### print\_stack\_trace

```python
print_stack_trace(context: int | None = None) -> None
```

Render a compact Rich call stack table followed by active frame context.

Args: context (int | None): Optional context line override for the active frame.

#### do\_context

```python
do_context(context: str) -> None
```

Set the number of source context lines shown on frame entry (`context`).

Args: context (str): Positive integer number of lines.

#### do\_break

```python
do_break(arg: str, temporary: Literal[0, 1] | bool = 0) -> None
```

Set a breakpoint or render a Rich table of active breakpoints (`b`).

Args: arg (str): Breakpoint location/condition, or empty to list breakpoints. temporary (Literal\[0, 1\] | bool): Whether the breakpoint is temporary.

#### do\_continue

```python
do_continue(arg: str) -> bool | None
```

Continue execution until next breakpoint (`c`), or evaluate `c(...)`.

Args: arg (str): Command argument, forwarded to evaluator when `c(...)`.

Returns: bool | None: Superclass return value, or `None` when executing `c(...)`.

#### do\_display

```python
do_display(arg: str) -> None
```

Add a watch expression or render a Rich table of watched expressions.

Args: arg (str): Expression to watch, or empty to list active watches.

#### do\_whatis

```python
do_whatis(arg: str) -> None
```

Display the type, MRO, and signature/size of an expression (`whatis`).

Args: arg (str): Expression string to inspect.

#### do\_psource

```python
do_psource(arg: str) -> None
```

Render syntax-highlighted source code for an object (`psource`).

Args: arg (str): Expression or symbol name whose source should be shown.

#### displayhook

```python
displayhook(obj: object) -> None
```

Render interactive REPL expression results with Rich pretty-printing.

Args: obj (object): Evaluated expression value.

#### do\_p

```python
do_p(arg: str) -> None
```

Rich-print the value of an expression (`p <expr>`).

Args: arg (str): Expression string to evaluate and print.

#### do\_pp

```python
do_pp(arg: str) -> None
```

Rich pretty-print the expanded value of an expression (`pp <expr>`).

Args: arg (str): Expression string to evaluate and pretty-print.

#### do\_pinfo

```python
do_pinfo(arg: str) -> None
```

Provide detailed information about an object in a Rich panel (`pinfo`).

Args: arg (str): Expression or object name to inspect.

#### do\_pinfo2

```python
do_pinfo2(arg: str) -> None
```

Provide extra detailed information about an object (`pinfo2`).

Args: arg (str): Expression or object name to inspect in full detail.

#### do\_args

```python
do_args(arg: str) -> None
```

Display the argument list of the current function in a Rich table (`a`).

Args: arg (str): Unused command argument string.

#### do\_interact

```python
do_interact(arg: str) -> None
```

Start an interactive IPython shell in the current frame (`interact`).

Args: arg (str): Unused command argument string.

#### do\_help

```python
do_help(arg: str = '') -> bool | None
```

Display the categorized command reference table or help for a command (`h`).

Args: arg (str): Optional command or topic name.

Returns: bool | None: Superclass return value when delegating to topic handlers.

## debug\_dojo.\_core.debugger.breakpoints

Breakpoint management, AST symbol lookup, and callable target resolution.

Functions:

| Name | Description |
| --- | --- |
| `has_active_breakpoints` | Return whether any `bdb.Breakpoint` is currently registered. |

### has\_active\_breakpoints

```python
has_active_breakpoints() -> bool
```

Return whether any `bdb.Breakpoint` is currently registered.

Returns: bool: `True` when at least one active breakpoint exists in `bdb`.

## debug\_dojo.\_core.debugger.session

Session lifecycle, excepthook handling, and debugger entrypoint functions.

Functions:

| Name | Description |
| --- | --- |
| `wrap_sys_excepthook` | Wrap `sys.excepthook` with `_bdb_quit_excepthook` once. |
| `set_trace` | Enter the internal DPDB debugger at the given or calling stack frame. |
| `setup` | Set internal DPDB as the active debugger. |
| `post_mortem` | Enter post-mortem debugging on the given or active exception traceback. |
| `pm` | Enter `dpdb` post-mortem debugging on the last unhandled exception. |
| `seed_cli_breakpoints` | Register CLI-supplied breakpoints before target execution. |
| `run_with_active_breakpoints` | Execute `call` under `dpdb` trace dispatch so active breakpoints fire. |

### wrap\_sys\_excepthook

```python
wrap_sys_excepthook() -> None
```

Wrap `sys.excepthook` with `_bdb_quit_excepthook` once.

### set\_trace

```python
set_trace(frame: FrameType | None = None) -> None
```

Enter the internal DPDB debugger at the given or calling stack frame.

Args: frame (FrameType | None): Target stack frame. Defaults to the caller's frame.

### setup

```python
setup() -> None
```

Set internal DPDB as the active debugger.

### post\_mortem

```python
post_mortem(tb: TracebackType | None = None) -> None
```

Enter post-mortem debugging on the given or active exception traceback.

Args: tb (TracebackType | None): Traceback to inspect (defaults to active exc\_info).

### pm

```python
pm() -> None
```

Enter `dpdb` post-mortem debugging on the last unhandled exception.

### seed\_cli\_breakpoints

```python
seed_cli_breakpoints(target_file: str, breaks: Sequence[str]) -> None
```

Register CLI-supplied breakpoints before target execution.

Args: target\_file (str): Path to the resolved target script. breaks (Sequence\[str\]): Breakpoint specifications (`line`, `file:line`, `func`).

### run\_with\_active\_breakpoints

```python
run_with_active_breakpoints(call: Callable[[], object]) -> None
```

Execute `call` under `dpdb` trace dispatch so active breakpoints fire.

Args: call (Callable\[\[\], object\]): Zero-argument callable executing the target.

## debug\_dojo.\_core.debugger.views

Visual formatting, Rich tables, and inspection panels for `dpdb`.

Functions:

| Name | Description |
| --- | --- |
| `is_runner_frame` | Return whether `frame` belongs to an internal runner or CLI framework module. |

### is\_runner\_frame

```python
is_runner_frame(frame: FrameType) -> bool
```

Return whether `frame` belongs to an internal runner or CLI framework module.

Args: frame (FrameType): Stack frame to inspect.

Returns: bool: `True` if the frame belongs to `debug_dojo`, `runpy`, `bdb`, `typer`, or `click`.

### Installer Subsystem

## debug\_dojo.\_core.installers

Module for installing opinionated debugging tools into Python's builtins.

Functions:

| Name | Description |
| --- | --- |
| `install_tools` | Configure `dpdb` and inject `b`, `p`, `i`, and `c` into `builtins`. |

### install\_tools

```python
install_tools() -> None
```

Configure `dpdb` and inject `b`, `p`, `i`, and `c` into `builtins`.

> > > install\_tools() import builtins all(callable(getattr(builtins, name)) for name in ("b", "p", "i", "c")) True

### Execution Subsystem

## debug\_dojo.\_core.execution

Module for executing targets with debugging tools.

Functions:

| Name | Description |
| --- | --- |
| `execute_with_debug` | Execute a target script, module, or command with `dpdb` and debugging tools. |

### execute\_with\_debug

```python
execute_with_debug(
    target_name: str, target_args: list[str], *, breaks: Sequence[str] | None = None
) -> None
```

Execute a target script, module, or command with `dpdb` and debugging tools.

Args: target\_name (str): The name of the script, module, or executable to run. target\_args (list\[str\]): Arguments to pass to the target. breaks (Sequence\[str\] | None): Optional CLI breakpoint specifications.

### Comparison Subsystem

## debug\_dojo.\_core.compare

Utilities for side-by-side inspection and comparison of Python objects.

This module provides functions to display attributes and methods of two objects in a visually appealing, side-by-side format in the terminal.

Functions:

| Name | Description |
| --- | --- |
| `get_object_attributes` | Extract and format non-callable attributes of an object. |
| `get_object_methods` | Extract and format public callable methods of an object. |
| `get_simplified_object_info` | Generate a simplified, Rich-formatted inspection output for an object. |
| `inspect_objects_side_by_side` | Display two Python objects side-by-side in the terminal using Rich. |

### get\_object\_attributes

```python
get_object_attributes(obj: object) -> list[str]
```

Extract and format non-callable attributes of an object.

Args: obj (object): The object to extract attributes from.

Returns: list\[str\]: A list of formatted strings, each representing an attribute.

### get\_object\_methods

```python
get_object_methods(obj: object) -> list[str]
```

Extract and format public callable methods of an object.

Args: obj (object): The object to extract methods from.

Returns: list\[str\]: A list of method names.

### get\_simplified\_object\_info

```python
get_simplified_object_info(obj: object) -> list[Text]
```

Generate a simplified, Rich-formatted inspection output for an object.

Handles basic Python types by displaying their value directly. For other objects, it lists their attributes and public methods.

Args: obj (object): The object to generate info for.

Returns: list\[Text\]: A list of Rich Text objects representing the object's information.

### inspect\_objects\_side\_by\_side

```python
inspect_objects_side_by_side(obj1: object, obj2: object) -> None
```

Display two Python objects side-by-side in the terminal using Rich.

Shows attributes and methods of both objects in a simplified, aligned format.

Args: obj1 (object): The first object to display. obj2 (object): The second object to display.
