Skip to main content

Pdb with Rich library.

Project description


PyPI version Python Version status

pdbr is intended to make the PDB results more colorful. it uses Rich library to carry out that.


Install with pip or your favorite PyPi package manager.

pip install pdbr


In order to use breakpoint(), set PYTHONBREAKPOINT with "pdbr.set_trace"

import os

os.environ["PYTHONBREAKPOINT"] = "pdbr.set_trace"

or just import pdbr

import pdbr

New commands


🍦 Icecream print.

(i)nspect / inspectall | ia


search | src

Search a phrase in the current frame. In order to repeat the last one, type / character as arg.


Get the local variables list as table.

varstree | vt

Get the local variables list as tree.



In order to use Rich's traceback, style, and theme, set setup.cfg.

style = yellow
use_traceback = True
theme = friendly


store_history setting is used to keep and reload history, even the prompt is closed and opened again.



In order to use Celery remote debugger with pdbr, use celery_set_trace as below sample. For more information see the Celery user guide.

from celery import Celery

app = Celery('tasks', broker='pyamqp://guest@localhost//')

def add(x, y):

    import pdbr; pdbr.celery_set_trace()

    return x + y


Instead of using telnet or nc, in terms of using pdbr style, pdbr_telnet command can be used.


Being able to use ipython, install pdbr with it like below or just install your own version.

pip install pdbr[ipython]


In order to user pdbr with pytest --pdb flag, add addopts setting in your pytest.ini.

addopts: --pdbcls=pdbr:RichPdb

Context Decorator

pdbr_context and apdbr_context (asyncio corresponding) can be used as with statement or decorator. It calls post_mortem if traceback is not none.

from pdbr import apdbr_context, pdbr_context

def foo():

def bar():
    with pdbr_context():

async def foo():

async def bar():
    async with apdbr_context():

Django DiscoverRunner

To being activated the pdb in Django test, change TEST_RUNNER like below. Unlike Django (since you are not allowed to use for smaller versions than 3), pdbr runner can be used for version 1.8 and subsequent versions.

TEST_RUNNER = "pdbr.runner.PdbrDiscoverRunner"



from fastapi import FastAPI
from pdbr.middlewares.starlette import PdbrMiddleware

app = FastAPI()

app.add_middleware(PdbrMiddleware, debug=True)

async def main():
    1 / 0
    return {"message": "Hello World"}


In order to catch the problematic codes with post mortem, place the middleware class.



Running pdbr command in terminal starts an IPython terminal app instance. Unlike default TerminalInteractiveShell, the new shell uses pdbr as debugger class instead of ipdb.

%debug magic sample


Django shell sample

Vscode user snippet

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select python.json.

Place the below snippet in json file for pdbr.

  "pdbr": {
        "prefix": "pdbr",
        "body": "import pdbr; pdbr.set_trace()",
        "description": "Code snippet for pdbr debug"

For Celery debug.

  "rdbr": {
        "prefix": "rdbr",
        "body": "import pdbr; pdbr.celery_set_trace()",
        "description": "Code snippet for Celery pdbr debug"



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pdbr, version 0.6.2
Filename, size File type Python version Upload date Hashes
Filename, size pdbr-0.6.2-py3-none-any.whl (13.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pdbr-0.6.2.tar.gz (13.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page