Debugging python code with wdb

How to use Wdb to debug python code

Posted on Sun 01 October 2017

While I was on PyConPL conference last year I heard about interesting debugger called wdb. Since then I don't have much chance to find out how it is to work with the tool. Yet I decided to write a quick blog post about it. Let's get started!

What exactly is wdb? From its github :

wdb is a full featured web debugger based on a client-server architecture.

It means that I can debug my python based applications inside my browser - even from the different computer. It's using web sockets under the hood. How can I debug for example django application?

Let's use my django application from Django Nginx blog series: repo. As it's in docker I only need to add an entry in docker-compose:

        - wdb
    image: kozea/wdb-server
        - "1984:1984"

The last thing is to add wdb support to

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")

application = get_wsgi_application()

from wdb.ext import WdbMiddleware
application = WdbMiddleware(application)

Let's see how it works:

How wdb works

I have to say that I'm really impressed by this project - awesome job! If you want to have code example go here.

That's all for today!

Cover image by Ritchie Valens on Unsplash.

tags: python, debugging, wdb,

If you find this blog post interesting please share:

Comments !