Skip to main content

A chatgpt enabled python debugger

Project description

image image image image Checked with pyright Ruff

chatpdb

chatpdb is an extension to ipdb that lets you ask questions while debugging your code.

Installation

pip install chatpdb

Ensure that you have OPENAI_API_KEY set in your environment.

Usage

In your code:

import chatpdb; chatpdb.set_trace()

Simply type y to receive a summary of the current code and stack trace.

> /Users/you/sample.py (9) test_function()
      8     
----> 9     import chatpdb; chatpdb.set_trace()
     10
ipdb> y
You are currently in a python debugger, etc.

Type y "prompt" to ask a question.

> /Users/you/sample.py (9) test_function()
      8     
----> 9     import chatpdb; chatpdb.set_trace()
     10
ipdb> y "what does chatpdb do in this case?"
You are currently in a python debugger, etc.

How does it work?

chatpdb uses the OpenAI API to generate responses to your questions. It uses the gpt-4-turbo model by default.

chatpdb will automatically include relevant context from the current frame and stack trace, as well as exception information if one has been raised.

Advanced

Usage

ipdb and pdb support many different entrypoints which chatpdb also supports.

import chatpdb; chatpdb.run('print("hello")')
import chatpdb; chatpdb.runcall(lambda x: x + 1, 1)
# chatpdb will launch on exception
# @chatpdb.iex is also supported
@chatpdb.cex
def sample_cex_function():
    raise
def sample_with_function():
    with chatpdb.launch_chatpdb_on_exception(): # or chatpdb.launch_ipdb_on_exception()
        raise
# See pdb documentation for pm (post-mortem) usage
import chatpdb; chatpdb.pm()

Configuration

You can use more specific environment variables to configure an OpenAI key and preferred model for chatpdb. The following environment variables are supported:

  • CHAT_PDB_OPENAI_API_KEY: Your OpenAI API key
  • CHAT_PDB_OPENAI_MODEL: The model to use for chatpdb. Default is 'gpt-4-turbo'

Project details


Download files

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

Source Distribution

chatpdb-0.1.3.tar.gz (24.7 kB view hashes)

Uploaded Source

Built Distribution

chatpdb-0.1.3-py3-none-any.whl (25.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page