Skip to main content

Debug your Python code with AI assistance

Project description

snooper-ai ๐Ÿ”

snooper-ai is a simple fork of PySnooper. It sends the entire execution trace (variable values you'll typically examine in a debugger) to an LLM for debugging, so it fully understands what happened in your code.

Disclaimer: This was implemented simply and may not be very robust. Feel free to submit issues.

Usage:

  1. Install
pip install snooper-ai
  1. Store your LLM api key (either anthropic or openai):
ANTHROPIC_API_KEY=xxx
OPENAI_API_KEY=xxx
  1. Add a decorator to the function you want to inquire:
from snooper_ai import snoop

@snoop()
def number_to_bits(number):
    if number:
        bits = []
        while number:
            number, remainder = divmod(number, 2)
            bits.insert(0, remainder)
        return bits
    else:
        return [0]

number_to_bits(6)
  1. Run the file
snoop run file.py
  1. Tell the LLM what you're confused about:
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  ๐Ÿ” snooper-ai: Debug your Python code with AI  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

What would you like to know about the code execution? (e.g. Error messages, unexpected behavior, etc.):
  1. Run it and get a detailed explanation!

  2. To choose which model you're using (This will be saved in your pyproject.toml):

snoop config

More info

This is what gets sent to the LLM. Refer to the original PySnooper for more details

New var:....... i = 9
New var:....... lst = [681, 267, 74, 832, 284, 678, ...]
09:37:35.881721 line        10         lower = min(lst)
New var:....... lower = 74
09:37:35.882137 line        11         upper = max(lst)
New var:....... upper = 832
09:37:35.882304 line        12         mid = (lower + upper) / 2
74 453.0 832
New var:....... mid = 453.0
09:37:35.882486 line        13         print(lower, mid, upper)
Elapsed time: 00:00:00.000344

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

snooper_ai-0.0.2.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snooper_ai-0.0.2-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file snooper_ai-0.0.2.tar.gz.

File metadata

  • Download URL: snooper_ai-0.0.2.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for snooper_ai-0.0.2.tar.gz
Algorithm Hash digest
SHA256 602a61473172093f90a0e9ffa645c768df9240ac6e9cb27627f63ad55cc9a124
MD5 0de3368c78172240cab77fc7ab0c0fd4
BLAKE2b-256 ff2d316d91c49b1c7f84d9b31bd5ec45b9c0d38328f629d55cfe6741d0b40a78

See more details on using hashes here.

File details

Details for the file snooper_ai-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: snooper_ai-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for snooper_ai-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 15155005249f52518ff0cb9f8bcbcd769c1fcf81a8b872079345931b1183505a
MD5 6da39119d53363052bbe96544399de2b
BLAKE2b-256 7de5c4c9699574219ac3c44a133c9fcd0c7d9e784c143e5345854b1e7c14e536

See more details on using hashes here.

Supported by

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