Skip to main content

IPython pdb 3

ipdbx is an improved version of ipdb that provides extra functionality and customisation.

Python 2 support has been dropped to make way for new features.

Use

ipdbx exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better introspection with the same interface as the pdb module.

Example usage:

import ipdbx
ipdbx.set_trace()
ipdbx.set_trace(context=5)  # will show five lines of code
                           # instead of the default three lines
                           # or you can set it via IPDB_CONTEXT_SIZE env variable
                           # or setup.cfg file
ipdbx.set_trace(pretrace='/useful/debug/tools.py')  # can be set via IPDB_PRETRACE
                                                   # env variable. pretrace also
                                                   # accepts the same type of args
                                                   # as ipdbx.run(), ipdbx.runcall()
                                                   # and ipdbx.runeval()
ipdbx.pm()
ipdbx.run('x[0] = 3')
result = ipdbx.runcall(function, arg0, arg1, kwarg='foo')
result = ipdbx.runeval('f(1,2) - 3')

Patching sys.breakpointhook to call ipdbx when calling breakpoint():

import ipdbx
import sys
sys.breakpointhook = ipdbx.set_trace

# You can also call set_trace with default arguments, likewise:

from functools import partial
sys.breakpointhook = partial(ipdbx.set_trace, context=30, pretrace='/my/favourite/things.py')

Arguments for ipdbx.set_trace

The ipdbx.set_trace function accepts the following optional parameters:

  • frame, a frame object (defaults to last);

  • context: int, which will show as many lines of code as defined;

  • cond: bool, which accepts boolean values (such as abc == 17) and will start ipdb’s interface whenever cond equals to True;

  • pretrace, which accepts a file path, a python statement string, or a code object, which it will execute immediately before starting the debugger.

Using configuration file

It’s possible to set up context using a .ipdb file on your home folder or setup.cfg on your project folder. You can also set your file location via env var $IPDB_CONFIG. Your environment variable has priority over the home configuration file, which in turn has priority over the setup config file. Currently, only context setting is available.

A valid setup.cfg is as follows

[ipdb]
context=5
pretrace=./file.py

A valid .ipdb is as follows

context=5
pretrace="import inspect"

The post-mortem function, ipdbx.pm(), is equivalent to the magic function %debug.

If you install ipdbx with a tool which supports setuptools entry points, an ipdbx script is made for you. You can use it to debug your python scripts like

$ bin/ipdbx mymodule.py

You can also enclose code with the with statement to launch ipdb if an exception is raised:

from ipdbx import launch_ipdb_on_exception

with launch_ipdb_on_exception():
    ...

Issues with stdout

Some tools, like nose fiddle with stdout.

If you use a tool that fiddles with stdout, you should explicitly ask for stdout fiddling by using ipdbx like this

import ipdbx
ipdbx.sset_trace()
ipdbx.spm()

from ipdbx import slaunch_ipdb_on_exception
with slaunch_ipdb_on_exception():
    ...

Development

ipdbx source code and tracker are at https://github.com/giladbarnea/ipdbx.

Pull requests should take care of updating the changelog HISTORY.txt.

Manual testing

To test your changes, make use of manual_test.py. Create a virtual environment, install IPython and run python manual_test.py and check if your changes are in effect. If possible, create automated tests for better behaviour control.

Metadata

Release files for ipdbx 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipdbx 1.0.4
File Size Uploaded
ipdbx-1.0.4.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ipdbx 1.0.4
File Interpreter ABI Platform
ipdbx-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / ipdbx-1.0.4.tar.gz

Download URL ipdbx-1.0.4.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0ffa7f8b160db9d7ea8206f62c1e72f1710e445897948c66fce0c80f2fb7f4f9
BLAKE2b-256 checksum
How to use checksums
563b60b5033aef7ff87b68cb62ff11c5e5f0e27b30b3f5023776ff84873d27c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.5

Release files / ipdbx-1.0.4-py3-none-any.whl

Download URL ipdbx-1.0.4-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66faeb82212f6fa2fd9ef7853de1999f9de34575dd5121826afba3532f1ec5da
BLAKE2b-256 checksum
How to use checksums
a05de216280b1d11ad93ba940b4bdb1ef5a256ad75618374d78454c8a7faf65a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page