|
| 1 | +# 🐍 Compython |
1 | 2 |
|
| 3 | +> **AI chat assistant for Obsidian with vault awareness, semantic search, one-click edits, and native Python execution.** |
| 4 | +
|
| 5 | +Compython is a fork of [Smart Composer](https://github.com/glowingjade/obsidian-smart-composer) that adds the ability to **write and run Python code directly inside Obsidian** — both manually by the user and autonomously by the AI model. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## ✨ What's new in Compython |
| 10 | + |
| 11 | +### Native Python Execution |
| 12 | + |
| 13 | +Every Python code block in the chat gets a **"Run Python"** button. Click it and the output appears inline — no terminal, no switching apps, no copy-paste. |
| 14 | + |
| 15 | +- Works with **any AI model** — local (Gemma, Qwen, LLaMA) or cloud (Claude, GPT, Gemini) |
| 16 | +- No tool calling required — based on markdown code block detection, so every model works |
| 17 | +- Output appears inline with stdout, stderr, and exit code |
| 18 | +- The vault path is automatically available as the `VAULT_PATH` environment variable inside scripts |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 🚀 Features (inherited from Smart Composer) |
| 23 | + |
| 24 | +- **Contextual Chat** — reference vault files with `@filename` syntax |
| 25 | +- **Apply Edit** — AI suggests edits to your notes with one-click apply |
| 26 | +- **Vault Search (RAG)** — semantic search across your entire vault |
| 27 | +- **MCP Support** — connect to external tools via Model Context Protocol |
| 28 | +- **Local Model Support** — Ollama, LM Studio, and any OpenAI-compatible provider |
| 29 | +- **Custom System Prompts** and **Prompt Templates** |
| 30 | +- Multiple AI providers: Anthropic, OpenAI, Gemini, Groq, DeepSeek, OpenRouter, and more |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## 📦 Installation |
| 35 | + |
| 36 | +### Manual installation |
| 37 | + |
| 38 | +1. Download the latest release: `main.js`, `manifest.json`, `styles.css` |
| 39 | +2. Create the folder: `YOUR_VAULT/.obsidian/plugins/compython/` |
| 40 | +3. Copy the 3 files into that folder |
| 41 | +4. In Obsidian: `Settings → Community plugins → reload` → enable **Compython** |
| 42 | + |
| 43 | +> ⚠️ If you have **Smart Composer** installed, disable or uninstall it first — they conflict since they register the same view type. |
| 44 | +
|
| 45 | +--- |
| 46 | + |
| 47 | +## ⚙️ Setting up Python execution |
| 48 | + |
| 49 | +1. Go to `Settings → Compython → Python Executor` |
| 50 | +2. Toggle **Enable Python execution** ON |
| 51 | +3. Set the **Python path**: |
| 52 | + - Windows: `python` or `C:\Python311\python.exe` |
| 53 | + - macOS/Linux: `python3` |
| 54 | +4. Configure timeout and confirmation preferences |
| 55 | +5. Done — every `python` code block in chat will now have a **Run Python** button |
| 56 | + |
| 57 | +### Using your vault path in scripts |
| 58 | + |
| 59 | +```python |
| 60 | +import os |
| 61 | + |
| 62 | +vault = os.environ.get("VAULT_PATH", ".") |
| 63 | +print(f"My vault is at: {vault}") |
| 64 | + |
| 65 | +# List all markdown files in the vault |
| 66 | +import pathlib |
| 67 | +notes = list(pathlib.Path(vault).rglob("*.md")) |
| 68 | +print(f"Found {len(notes)} notes") |
| 69 | +``` |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## 🔧 Development |
| 74 | + |
| 75 | +```bash |
| 76 | +git clone https://github.com/disonfranco/compython |
| 77 | +cd compython |
| 78 | +npm install |
| 79 | +npm run dev # watch mode |
| 80 | +npm run build # production build |
| 81 | +``` |
| 82 | + |
| 83 | +Copy `main.js`, `manifest.json`, and `styles.css` to your vault's plugin folder after building. |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## 🗺️ Roadmap |
| 88 | + |
| 89 | +- [ ] Auto-run Python after AI response (agentic loop for local models) |
| 90 | +- [ ] Plot rendering — display matplotlib figures inline in chat |
| 91 | +- [ ] Session state — persistent Python environment across executions |
| 92 | +- [ ] Virtual environment support — point to a venv instead of system Python |
| 93 | +- [ ] Safety sandbox — optional restricted execution mode |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## 🙏 Credits |
| 98 | + |
| 99 | +Compython is built on top of [Smart Composer](https://github.com/glowingjade/obsidian-smart-composer) by [@glowingjade](https://github.com/glowingjade) and contributors. All original features and architecture are theirs — Compython adds the Python execution layer on top. |
| 100 | + |
| 101 | +**Authors of the Python execution feature:** |
| 102 | +- [Dison Franco](https://github.com/disonfranco) — concept, testing, and direction |
| 103 | +- [Claude](https://claude.ai) (Anthropic) — implementation |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## 📄 License |
| 108 | + |
| 109 | +MIT — same as the original Smart Composer. |
0 commit comments