Python breakpoint() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in

Definition

In Python 3.7 and newer, breakpoint() stops your program at that line and opens the debugger, by default pdb. There you can inspect variables (p total), step to the next line (n), continue (c), or quit (q). It replaces the older import pdb; pdb.set_trace().

What it actually does is call sys.breakpointhook(). The PYTHONBREAKPOINT environment variable controls that hook: 0 disables every breakpoint, and a dotted name such as ipdb.set_trace chooses a different debugger. The examples below use these controls so they run without stopping.

breakpoint() is a built-in function: it lives in the builtins module, so it is always available without an import. Added in Python 3.7.

Syntax

Put it on the line where you want to stop.

python
def total_price(items):
    total = sum(items)
    breakpoint()          # pdb opens here when run normally
    return total
CallWhat it does
breakpoint()Opens pdb at this line.
PYTHONBREAKPOINT=0Environment setting that turns breakpoints off.
sys.breakpointhook = fCalls f() instead of the debugger.
breakpoint(*args)Arguments are passed on to the hook.

Remove breakpoints before committing code, or run tests with PYTHONBREAKPOINT=0 so a forgotten one cannot hang them.

Library declarations
python
breakpoint(*args, **kws)
# calls sys.breakpointhook(*args, **kws); added in Python 3.7

Parameters

ParameterDescription
*args, **kwsOptional. Passed unchanged to sys.breakpointhook(); the default pdb hook ignores them.

Return Value

Return ValueDescription
anyWhatever the hook returns; normally None.

Python Examples

Example 1 — Replace the Debugger with a Custom Hook

Point sys.breakpointhook at your own function so every breakpoint just logs a message.

python
import sys


def log_hook(*args, **kwargs):
    print("breakpoint reached (custom hook, no debugger)")


sys.breakpointhook = log_hook

total = 0
for n in [3, 4]:
    total += n
    breakpoint()
print("total:", total)

How It Works

  1. A replaceable hook. breakpoint() calls whatever function is stored in sys.breakpointhook.
  2. No pause. The custom hook prints and returns, so the loop continues.
  3. Once per call. The loop runs twice, so the message appears twice.
  4. Restore the default. sys.__breakpointhook__ holds the original hook if you need pdb again.

Example 2 — Turn Breakpoints Off with PYTHONBREAKPOINT=0

Set the environment variable from inside the script and watch breakpoint() do nothing.

python
import os

os.environ["PYTHONBREAKPOINT"] = "0"

print("before")
breakpoint()
print("after: breakpoint() was skipped")

How It Works

  1. Checked on every call. The default hook reads PYTHONBREAKPOINT each time a breakpoint is hit.
  2. Zero means off. With the value "0", the call returns immediately.
  3. Usually set outside. In practice you set it in the shell, for example PYTHONBREAKPOINT=0 python app.py.
  4. Safe for automation. Test runners and servers can disable stray breakpoints this way.

Example 3 — Send Breakpoints to Another Callable

Point PYTHONBREAKPOINT at builtins.print and pass arguments through breakpoint().

python
import os

os.environ["PYTHONBREAKPOINT"] = "builtins.print"

for step in range(1, 3):
    breakpoint("checkpoint", step)

os.environ["PYTHONBREAKPOINT"] = "0"
breakpoint()
print("done")

How It Works

  1. Dotted name. The default hook imports builtins and calls its print instead of pdb.
  2. Arguments pass through. breakpoint("checkpoint", step) becomes print("checkpoint", step).
  3. Switch at runtime. Setting the variable to "0" disables the last breakpoint.
  4. Other debuggers. The same mechanism selects tools like ipdb.set_trace or an IDE's debugger.

Frequently Asked Questions

It pauses the program and opens the debugger (pdb by default) at that line. Added in Python 3.7.
Set the environment variable PYTHONBREAKPOINT=0 before running the program.
n (next line), s (step into), c (continue), p expr (print a value), l (list code), q (quit).
Set PYTHONBREAKPOINT to the debugger's function, for example PYTHONBREAKPOINT=ipdb.set_trace.
By default yes, but breakpoint() goes through sys.breakpointhook, so it can be disabled or redirected without editing code.

Next: bytearray()

Create a mutable, resizable sequence of bytes.

bytearray() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful