{"id":13442444,"url":"https://github.com/Kozea/wdb","last_synced_at":"2025-03-20T14:30:33.603Z","repository":{"id":654006,"uuid":"6093324","full_name":"Kozea/wdb","owner":"Kozea","description":"An improbable web debugger through WebSockets","archived":false,"fork":false,"pushed_at":"2022-12-06T14:33:43.000Z","size":19260,"stargazers_count":1579,"open_issues_count":40,"forks_count":120,"subscribers_count":70,"default_branch":"master","last_synced_at":"2025-03-12T11:11:50.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kozea.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-05T16:40:23.000Z","updated_at":"2025-02-03T19:12:18.000Z","dependencies_parsed_at":"2023-01-13T16:22:03.189Z","dependency_job_id":null,"html_url":"https://github.com/Kozea/wdb","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kozea%2Fwdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kozea%2Fwdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kozea%2Fwdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kozea%2Fwdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kozea","download_url":"https://codeload.github.com/Kozea/wdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244629974,"owners_count":20484288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:45.758Z","updated_at":"2025-03-20T14:30:33.597Z","avatar_url":"https://github.com/Kozea.png","language":"Python","funding_links":[],"categories":["Python","Mini Program","Debugging Tools","资源列表","调试工具","Debugging Tools [🔝](#readme)","工具与库","Awesome Python"],"sub_categories":["Utility","调试工具","调试器","Debugging Tools"],"readme":"# wdb - Web Debugger\n[![Build Status](https://travis-ci.org/Kozea/wdb.svg?branch=master)](https://travis-ci.org/Kozea/wdb)\n[![Coverage Status](https://coveralls.io/repos/Kozea/wdb/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/Kozea/wdb?branch=master)\n\n[![](https://raw.github.com/Kozea/wdb/master/wdb.png)](https://raw.github.com/Kozea/wdb/master/wdb-lg.png)\n\n\n## Description\n\n\n**wdb** is a full featured web debugger based on a client-server architecture.\n\nThe wdb server which is responsible of managing debugging instances along with browser connections (through websockets) is based on [Tornado](http://www.tornadoweb.org/).\nThe wdb clients allow step by step debugging, in-program python code execution, code edition (based on [CodeMirror](http://codemirror.net/)) setting breakpoints...\n\nDue to this architecture, all of this is fully compatible with **multithread** and **multiprocess** programs.\n\n**wdb** works with python 2 (2.6, 2.7), python 3 (3.2, 3.3, 3.4, 3.5) and pypy.\nEven better, it is possible to debug a python 2 program with a wdb server running on python 3 and vice-versa or debug a program running on a computer with a debugging server running on another computer inside a web page on a third computer!\n\nEven betterer, it is now possible to pause a currently running python process/thread using code injection from the web interface. (This requires gdb and ptrace enabled)\n\nIn other words it's a very enhanced version of pdb directly in your browser with nice features.\n\n\n## Installation:\n\nGlobal installation:\n\n```\n    $ pip install wdb.server\n```\n\nIn virtualenv or with a different python installation:\n\n```\n    $ pip install wdb\n```\n\n(You must have the server installed and running)\n\n## Quick test\n\nTo try wdb, first you have to start the wdb server:\n\n```\n    $ wdb.server.py \u0026\n```\n\nOptionally, you can automatically activate daemons with systemd (socket activation):\n\n```\n    $ cd /etc/systemd/system\n    # curl -O https://raw.githubusercontent.com/Kozea/wdb/master/server/wdb.server.service\n    # curl -O https://raw.githubusercontent.com/Kozea/wdb/master/server/wdb.server.socket\n    # systemctl enable wdb.server.socket\n    # systemctl start wdb.server.socket\n```\n\nNext run:\n\n```\n    $ python -m wdb your_file.py\n```\n\nWdb will open a debugging window right in your browser, paused at the beginning of your program.\n\nYou can access to \u003chttp://localhost:1984/\u003e to have an overview of the server.\n\nNB: You have to start the server only once. Multiple Debugging sessions can be run simultaneously without problem.\n\nThis is not the only way to debug a program, see below.\n\n\n## Usage\n\n### Setting trace\n\nTo debug any program, with the server on, just add:\n\n```python\n    import wdb\n    wdb.set_trace()\n```\n\nanywhere in your code. Your program will stop at the set_trace line. (Just like pdb)\n\n\n### Tracing code\n\nTo inspect your code on exception, you can do the following:\n\n```python\n    from wdb import trace\n    with trace():\n        wrong_code()\n```\n\nAny exception during `wrong_code` will launch a debugging session.\n\nYou can also use the `start_trace()` and `stop_trace` methods.\n(It's better to put the `stop_trace` in a finally block to avoid tracing all your program after an exception.)\n\n\n### Debugging web servers\n\nwdb provides some tools to make it work nicely with different webservers:\n\n\n#### Wsgi servers\n\nFor wsgi servers you can use the `WdbMiddleware`:\n\n```python\n    from wdb.ext import WdbMiddleware\n    wsgi_app = Whathever_wsgi_server_lib()\n    my_app = WdbMiddleware(wsgi_app)\n    my_app.serve_forever()\n```\n\n##### Flask\n\nor using Flask:\n\n```python\n    from flask import Flask\n    from wdb.ext import WdbMiddleware\n    app = Flask(__name__)\n    app.debug = True\n    app.wsgi_app = WdbMiddleware(app.wsgi_app)\n    app.run(use_debugger=False) # Disable builtin Werkzeug debugger\n```\n\nyou can also use the [Flask-Wdb](https://github.com/techniq/flask-wdb/) extension\n\n```python\n    from flask import Flask\n    from flask_wdb import Wdb\n\n    app = Flask(__name__)\n    app.debug = True\n    Wdb(app)\n\n    app.run()\n```\n\n##### Django\n\nor using django:\n\nAdd the middleware in your `wsgi.py`:\n\nAfter:\n\n```python\n    from django.core.wsgi import get_wsgi_application\n    application = get_wsgi_application()\n```\n\nAdd this:\n\n```python\n    from wdb.ext import WdbMiddleware\n    application = WdbMiddleware(application)\n```\n\nAnd in your `settings.py`, activate exception propagation:\n\n```python\n    DEBUG = True\n    DEBUG_PROPAGATE_EXCEPTIONS = True\n```\n\n##### CherryPy\n\nor using CherryPy:\n\n```python\nimport cherrypy\nfrom wdb.ext import WdbMiddleware\n\nclass HelloWorld(object):\n    @cherrypy.expose\n    def index(self):\n        undefined_method() # This will fail\n        return \"Hello World!\"\n\ncherrypy.config.update({'global':{'request.throw_errors': True}})\napp = cherrypy.Application(HelloWorld())\napp.wsgiapp.pipeline.append(('debugger', WdbMiddleware))\n\ncherrypy.quickstart(app)\n```\n\n#### Tornado\n\nIn tornado, which is not a wsgi server, you can use the `wdb_tornado` function which will monkey patch the execute method on RequestHandlers:\n\n```python\n    from wdb.ext import wdb_tornado\n    from tornado.web import Application\n    my_app = Application([(r\"/\", MainHandler)])\n    if options.debug:\n        wdb_tornado(my_app)\n    my_app.listen(8888)\n```\n\n#### Page loading time become slow\n\n\nIf wdb slows down too much of your application (tracing all the things takes time), you can start it disabled with:\n\n```python\n    my_app = WdbMiddleware(wsgi_app, start_disabled=True)  # or\n    wdb_tornado(my_app, start_disabled=True)\n```\n\nThen when you get an exception just click on the on/off button.\n\n\n## Remote debugging\n\nYou can easily do remote debugging with wdb:\n\nLet's say you want to run a program `p.py` on computer A and you want to debug it on computer B.\n\nStart wdb server on computer A and launch this:\n\n```\n    WDB_NO_BROWSER_AUTO_OPEN=True python -m wdb p.py\n```\n\nAnd open a browser on computer B at the url given by wdb log.\n\n\nNow you can also run wdb server on a computer C and run on computer A:\n\n```\n    WDB_NO_BROWSER_AUTO_OPEN=True WDB_SOCKET_SERVER=computerC.addr WDB_SOCKET_PORT=19840 python -m wdb p.py\n```\n\nAnd go with computer B to http://computerC/debug/session/[uuid in log] there you can step into p.py running in computer A. Yay !\n\nYou can use different configurations:\n\nSee `wdb.server.py --help` for changing ports on server and these environnement vars for wdb instances:\n\n```\nWDB_SOCKET_SERVER         # WDB server host\nWDB_SOCKET_PORT           # WDB server socket port\nWDB_WEB_SERVER            # WDB server host for browser openning\nWDB_WEB_PORT              # WDB server http port\nWDB_NO_BROWSER_AUTO_OPEN  # To disable the automagic browser openning (which can't be done if the browser is not on the same machine)\n```\n### Docker\n\nIf you are developing locally with [Docker](http://www.docker.com/), you can\nalso use wdb to debug a code running inside a container. The basic setup looks\nlike this:\n\n1. Start `wdb.server.py ` running in a container and expose port `1984` to your\n   host computer, this will server the debugging web server.\n2. Start debugging in your app container, making sure to set `WDB_SOCKET_SERVER`\n   to the address of the server container, and point it to the expoed port\n   `19840` on that server.\n3. When a trace is reached, open up `http://\u003cyour-docker-hostname\u003e:1984`\n\nI will walk through this process in detail, using\n[Docker Compose](https://docs.docker.com/compose/) to set up the containers.\n\nLet's say your `docker-compose.yml` looks like\n[their example for using with Django](https://docs.docker.com/compose/django/):\n\n```yaml\ndb:\n  image: postgres\nweb:\n  build: .\n  command: python manage.py runserver 0.0.0.0:8000\n  volumes:\n    - .:/code\n  ports:\n    - \"8000:8000\"\n  links:\n    - db\n```\n\nNext lets add the wdb server part now and tell the web to link to it:\n\n```yaml\ndb:\n  image: postgres\nweb:\n  build: .\n  command: python manage.py runserver 0.0.0.0:8000\n  volumes:\n    - .:/code\n  ports:\n    - \"8000:8000\"\n  links:\n    - db\n    - wdb\n  environment:\n    WDB_SOCKET_SERVER: wdb\n    WDB_NO_BROWSER_AUTO_OPEN: True\nwdb:\n  image: kozea/wdb\n  ports:\n    - \"1984:1984\"\n```\n\nAnd add `wdb` to your `requirements.txt` in your web app:\n\n```bash\n$ echo 'wdb' \u003e\u003e requirements.txt\n```\n\nNow we can use `wdb.set_trace()` in our python app.\n\n```python\n# ... some code\nimport wdb\nwdb.set_trace()\n```\nThen you have to rebuild your web application and start everything up again\n\n```bash\n$ docker-compose stop\n$ docker-compose build web\n$ docker-compose up\n```\n\n\nNow you can access `http://\u003clocal docker server\u003e:1984`, to\nsee the traces as they come up in your app.\n\n## In browser usage\n\nOnce you are in a breakpoint or in an exception, you can eval all you want in the prompt under the code.\nMulti-lines are partially supported using `[Shift] + [Enter]`.\nThere is now help available by clicking on the top help button.\n\nAs of now the following special commands are supported during breakpoint:\n\n    * .s or [Ctrl] + [↓] or [F11]    : Step into\n    * .n or [Ctrl] + [→] or [F10]    : Step over (Next)\n    * .r or [Ctrl] + [↑] or [F9]     : Step out (Return)\n    * .c or [Ctrl] + [←] or [F8]     : Continue\n    * .u or [F7]                     : Until (Next over loops)\n    * .j lineno                      : Jump to lineno (Must be at bottom frame and in the same function)\n    * .b arg                         : Set a session breakpoint, see below for what arg can be*\n    * .t arg                         : Set a temporary breakpoint, arg follow the same syntax as .b\n    * .z arg                         : Delete existing breakpoint\n    * .l                             : List active breakpoints\n    * .f                             : Echo all typed commands in the current debugging session\n    * .d expression                  : Dump the result of expression in a table\n    * .w expression                  : Watch expression in current file (Click on the name to remove)\n    * .q                             : Quit\n    * .h                             : Get some help\n    * .e                             : Toggle file edition mode\n    * .g                             : Clear prompt\n    * .i [mime/type;]expression      : Display the result in an embed, mime type is auto detected on linux and defaults to \"text/html\" otherwise\n    * iterable!sthg                  : If cutter is installed, executes cut(iterable).sthg\n    * expr \u003e! file                   : Write the result of expr in file\n    * !\u003c file                        : Eval the content of file\n    * [Enter]                        : Eval the current selected text in page, useful to eval code in the source\n    *\n    * * arg is using the following syntax:\n    *   [file/module][:lineno][#function][,condition]\n    * which means:\n    *   - [file]                    : Break if any line of `file` is executed\n    *   - [file]:lineno             : Break on `file` at `lineno`\n    *   - [file][:lineno],condition : Break on `file` at `lineno` if `condition` is True (ie: i == 10)\n    *   - [file]#function           : Break when inside `function` function\n    *\n    * File is always current file by default and you can also specify a module like `logging.config`.\n\nYou can also eval a variable in the source by middle clicking on it.\nYou can add/remove a breakpoint by clicking on the line number.\n\nNB: Hotkeys with arrows are purposely not triggered in the eval prompt to avoid conflicts when typing.\n\n\n## Wdb Server\n\nTo see which debugging session are currently open, open your browser at \u003chttp://localhost:1984/\u003e.\nYou can also close crashed session.\n\nFrom there you should also see all python process and their threads running and you can try to pause them during their execution to do step by step debugging and current variable inspection. **This is highly experimental and requires gdb and a kernel with ptrace enabled to inject python code into a running python process.**\nIf you get `ptrace: Operation not permitted.` you will have to enable it.\n\nDepending on your system it might work with:\n```bash\necho 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope\n```\n\nMake sure that wdb is installed for the python version running the program too.\n\n\n## Importing wdb each time is exhausting\n\nYes to avoid that, you can add a `w` builtin at the beggining of your application:\n\n\n```python\n    from wdb.ext import add_w_builtin\n    add_w_builtin()\n```\n\nyou can now use the `w` object any where in your code:\n\n```python\n    my_code()\n    w.tf  # Stop next line\n    doubtful_code()\n```\n\n\n```python\n    my_code()\n    with w.trace():\n        doubtful_code()\n```\n\n## Code completion\n\nWdb has dynamic code completion in eval prompt thanks to [jedi](https://github.com/davidhalter/jedi).\n\n\n## FAQ\n\n### In Firefox opened debugging pages are not closed when done\n\nIt's a firefox config flag, visit `about:config` and set:\n`dom.allow_scripts_to_close_windows` to `true`\n\n### The logs are spammed with 'parsing Python module'\n\nIf your logging configuration is set to display DEBUG logs, you may see a log for every imported file in your project any time WDB is active, like so:\n\n```\nDEBUG 2017-07-16 13:15:03,772 index 49835 123145573191680 parsing Python module /project/.virtualenv/python-3.6.1/lib/python3.6/site-packages/package/file.py for indexing\n```\n\n\nTo silence only this message, add a config for the importmagic module. For example: \n\n```    \nLOGGING = {\n    ...\n    'loggers': {\n        ...\n        'importmagic.index': {\n            'level': 'ERROR',\n            'propagate': False,\n        },\n    },\n}\n```\n\n\n## Contribute\n\nAll contributions are more than welcomed, use the fork luke !\n\nOr you still can use your money =)\n\n[![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=paradoxxx_zero\u0026url=https://github.com/Kozea/wdb\u0026title=Wdb\u0026tags=github\u0026category=software)\n[![gittip](http://i.imgur.com/IKcQB2P.png)](https://www.gittip.com/paradoxxxzero/)\n\n\n## Test\n\nWdb is now partially tested, so if you want to contribute be sure to run the test suite:\n\n```\n    $ pip install pytest\n    $ pip install -e client -e server\n    $ cd test\n    $ py.test\n```\n\nFeel free to add tests !\n\n## Author\n\n[Florian Mounier](http://github.com/paradoxxxzero) @ [Kozea](http://kozea.fr/)\n\n\n## Licence\n\nThis library is licensed under GPLv3\n\nwdb - An improbable web debugger through WebSockets\n\n\n    wdb Copyright (c) 2012-2016  Florian Mounier, Kozea\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKozea%2Fwdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKozea%2Fwdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKozea%2Fwdb/lists"}