AI-powered coding assistant plugin for Spyder IDE
Project description
Spyder Code Agent
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
.pyfiles 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/v1orhttp://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
showtracebackfunction into the IPython shell. Every error is written to a temporary file (~/.agent_last_error) and picked up by aQTimer. - 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:
- Fork the repo.
- Create a feature branch.
- Install development dependencies:
pip install -e . - Test your changes in Spyder.
- Submit a PR.
📜 License
MIT License. See LICENSE for details.
Made with ❤️ for the data science and Machine Learning community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spyder_code_agent-0.1.0.tar.gz.
File metadata
- Download URL: spyder_code_agent-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbe6dd2541c9d9fd27cab49bd8de69b333433389b9e3f439b14b6e353dc89e7
|
|
| MD5 |
4c19c455454a13a49314f1d12b636625
|
|
| BLAKE2b-256 |
2f8f204f98744a4773d48d9044c5ccb75895c43dc6db92146d487285e4e9942a
|
File details
Details for the file spyder_code_agent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spyder_code_agent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff4288e7f27d417d6c79ce59f3f500354bcd5bfa31d4fef61377fb1883415e93
|
|
| MD5 |
1ceb0f43e2448c9fd2bdcc6e4518b84b
|
|
| BLAKE2b-256 |
ccaf8fd8de138efc73542ad536a27ce7201071e07607774bc0007f6cb159a8ad
|