Skip to main content

AI-powered coding assistant plugin for Spyder IDE

Project description

Spyder Code Agent

Python Spyder License

AI‑powered coding assistant for Spyder IDE – automatically detects runtime errors in your Python/ML scripts and fixes them with one click.

Overview

Spyder Code Agent is a plugin that turns Spyder into a self‑debugging IDE. It listens to errors thrown in the IPython console, sends the relevant code (your selected files + current editor) to any OpenAI‑compatible LLM, and presents a ready‑to‑apply fix. No manual copy‑paste of tracebacks.

Perfect for machine learning and data science workflows where you frequently tweak code and run into KeyError, ValueError, shape mismatches, or missing imports.

✨ Key Features

  • Automatic error capture – Hooks into Spyder's IPython console; no need to type anything.
  • Selective file context – Choose exactly which .py files the agent can see (not your whole project).
  • One‑click code replacement – After the agent suggests a fix, click Apply Fix and the file is updated instantly.
  • Works with any OpenAI‑compatible API – Use OpenAI, local LLMs (via vLLM, Ollama, LM Studio), or any custom endpoint.
  • Persistent API settings – Base URL, API key, and model name are saved in ~/.agent_config.
  • Built for Spyder 6+ – Seamlessly docks into the IDE.

📋 Prerequisites

  • Spyder IDE 6.0 or higher
  • Python 3.8+
  • An OpenAI‑compatible API endpoint and key (e.g., OpenAI, Groq, LocalAI, etc.)

⚙️ Installation

From PyPI (recommended)

pip install spyder-code-agent

From source (for development)

git clone https://github.com/kasra7900/Spyder-Code-Agent.git
cd Spyder-Code-Agent
pip install -e .

🚀 Usage

1. First launch – API settings

When you first open the Code Agent pane, it will automatically show the API Settings dialog:

  • Base URL – e.g., https://api.openai.com/v1 or http://localhost:1234/v1
  • API Key – your secret key
  • Model Name – e.g., Deepseek v3, gpt-4, llama3, codellama

Save the settings – they are stored in ~/.agent_config and reused next time.

Tip: You can change these later by deleting the config file (~/.agent_config) and restarting Spyder – the dialog will appear again.

2. Add files to the context

Use the + Add file button to select Python files (.py) that the agent should be allowed to read. These files will be included in every analysis.

  • You can add multiple files.
  • The plugin does not scan your whole project – only the files you explicitly add.

3. Run your code as usual

Write your ML script (e.g., data loading, model training) in the Spyder editor. Execute it in the IPython console.

4. When an error occurs…

The plugin captures the traceback automatically. It then:

  • Combines the error message + stack trace
  • Adds the content of all added files + the current editor content
  • Sends everything to the LLM

Within seconds, the agent replies with:

  • Error type (e.g., KeyError, IndexError)
  • Description (plain English)
  • Solution (explanation + fixed code snippet)
  • Fixed code (the complete corrected file)

5. Apply the fix

If you see a fix you trust, click the ✅ Apply Fix button. The plugin will:

  • Replace the target file (if the agent specified a filename) or the current editor content
  • Reload the file in Spyder automatically

The error is resolved – no manual editing required.

🔧 Example workflow

Let’s say you have a script train.py:

import pandas as pd
df = pd.read_csv('data.csv')
X = df.drop('target', axis=1)   # but the column is actually 'label'

Running this raises KeyError: 'target'. The agent sees the error, reads train.py (added to context), and suggests:

❌ KeyError
Description: Column 'target' does not exist in the DataFrame.
Solution: Change 'target' to the correct column name 'label'.
Fixed code:
   X = df.drop('label', axis=1)

You click Apply Fix – the file is updated instantly.

⚙️ Under the hood

  • Error hook: The plugin injects a custom showtraceback function into the IPython shell. Every error is written to a temporary file (~/.agent_last_error) and picked up by a QTimer.
  • LLM prompt: The agent constructs a strict JSON prompt (error type, description, solution, fixed code, fixed file). The LLM must respond in that exact format.
  • File modification: When you click Apply Fix, the plugin writes the new content to the corresponding file path (or to the current editor if no file path is given). It creates no backup by default – be sure to use version control.

📄 Configuration

The plugin stores settings in ~/.agent_config (JSON). Example:

{
  "base_url": "https://api.openai.com/v1",
  "api_key": "sk-...",
  "model_name": "gpt-4"
}

You can edit this file manually, but it’s easier to use the dialog that appears on first launch.

🤝 Contributing

Issues and pull requests are welcome! To contribute:

  1. Fork the repo.
  2. Create a feature branch.
  3. Install development dependencies: pip install -e .
  4. Test your changes in Spyder.
  5. Submit a PR.

📜 License

MIT License. See LICENSE for details.


Made with ❤️ for the data science and Machine Learning community

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

spyder_code_agent-0.1.2.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

spyder_code_agent-0.1.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file spyder_code_agent-0.1.2.tar.gz.

File metadata

  • Download URL: spyder_code_agent-0.1.2.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for spyder_code_agent-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f6377cd708219bd92c6cdc00c0f31be19f4b8d7e6f9ca561a595a9f64003bf50
MD5 142ada3482d1dce8e2157e3fad895f56
BLAKE2b-256 16c9547d13e79f0496d19dfb03ec674c423bf0f7509f33a1b9d30ea7ba580a56

See more details on using hashes here.

File details

Details for the file spyder_code_agent-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for spyder_code_agent-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c663b08a85a9411eb1f210eaf9485d0cda7855e0db57186c6bd0ce2c8a33ff5
MD5 afa36396e6898408f64cb5c34423557c
BLAKE2b-256 07f3174f2a1e442560d2523faff652d10fb05ba074192a0b2f413589f9637155

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