Skip to main content

Debug your Python code with AI assistance

Project description

snooper-ai ๐Ÿ”

snooper-ai is a simple fork of PySnooper. It simply sends the entire execution trace 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. Store your LLM api key (either claude 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

Installation with Pip

The best way to install snooper-ai is with Pip:

$ pip install snooper-ai

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.1.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.1-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snooper_ai-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 45cc13a8cdf811c26cee995923010d9980ec17167a2c9b16a3a31196d9a5840f
MD5 d42d1ca5550f5a434a376c13cbfa1226
BLAKE2b-256 73634e4bc2213be69cbb29b661eba3577fa8e205502573fbea754f74553a7d9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: snooper_ai-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a5e5e5deda8d967b29632c2d52259dbb15cd1f31ed5cb0fe9610d4712568e04
MD5 cfc6f1108208f8f5f518a74f5aa0c491
BLAKE2b-256 e2707c15db0bfccb41549f3a6e04bdcfc71ff8f5598fb7595a2a7f5bcc557c6d

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