AI-powered coding assistant for JupyterLab using Claude
Project description
Jupyter Claude Assistant
An AI-powered coding assistant for JupyterLab and Jupyter Notebook, powered by Claude (Anthropic).
Works as both a JupyterLab server extension (with REST API) and a CLI tool (jca) for working with .py and .ipynb files from the terminal.
Features
| Feature | Description |
|---|---|
| ๐ฌ Chat | Ask Claude anything about your code with full notebook context |
| โจ Complete | Complete partial code cells or suggest the next cell in a notebook |
| ๐ Assignment Mode | Paste a problem statement โ get a fully written, explained notebook solution |
| ๐ง Fix Errors | Paste code + error โ get a working fix with explanation |
| ๐ Conda Aware | Auto-detects active environment, Python version, and installed packages |
| ๐ง Persistent Memory | SQLite database stores interactions and improves suggestions over time |
| ๐ Web Search | Search PyPI, GitHub, and Stack Overflow for packages and solutions |
| ๐ฅ๏ธ CLI Tool | jca command-line tool for non-JupyterLab workflows |
Installation
Prerequisites
- Python 3.9+
- Anaconda or Miniconda (recommended)
- JupyterLab 4.0+ (for server extension)
- An Anthropic API key
Install
# Install the package
pip install jupyter-claude-assistant
# Or install from source
git clone https://github.com/jbrown54-oss/jupyter-claude-assistant
cd jupyter-claude-assistant
pip install -e .
# Enable the server extension
jupyter server extension enable --py jupyter_claude_assistant
Set Your API Key
# Option 1: Environment variable (recommended)
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
# Option 2: JCA config file
jca config --set-key sk-ant-your-key-here
# Option 3: Set in JupyterLab settings panel after launching
Usage
In JupyterLab (Server Extension + HTML Panel)
-
Start JupyterLab:
jupyter lab -
The Claude Assistant panel is accessible at:
- Via proxy:
http://localhost:8888/jupyter-claude/static/panel.html - Via widget (in a notebook cell): See below
- Via proxy:
-
Use REST API from any notebook:
import requests # Chat with Claude r = requests.post('http://localhost:8888/jupyter-claude/chat', json={"message": "How do I normalize a pandas DataFrame?"}, cookies={"username-localhost-8888": "..."}) # Your Jupyter token print(r.json()['response'])
In Jupyter Notebook (Widget UI)
Open a new notebook cell and run:
from jupyter_claude_assistant import show_panel
show_panel() # Opens interactive panel with all features
This creates an interactive panel with tabs for Chat, Complete, Assign, Fix, and Environment info.
CLI Tool
After installation, the jca command is available:
# Chat about your code
jca chat "How do I read multiple CSV files into one dataframe?"
# Chat with notebook context
jca chat "What does this notebook do?" --notebook myanalysis.ipynb
# Explain a notebook or script
jca explain myanalysis.ipynb # Explain entire notebook
jca explain myanalysis.ipynb --cell 3 # Explain cell 3
jca explain myscript.py # Explain a Python file
# Fix errors
jca fix myanalysis.ipynb # Auto-find and fix error cell
jca fix myanalysis.ipynb --cell 5 # Fix specific cell
jca fix myscript.py # Run script and fix any runtime errors
# Complete an assignment
jca assign "Build a linear regression model on the Boston housing dataset with cross-validation" \
--output solution.ipynb
# Code completion
jca complete notebook.ipynb # Complete last code cell
jca complete notebook.ipynb --cell 4 # Complete specific cell
# Search for packages and solutions
jca search "time series forecasting"
jca search "dataframe pivot" --source stackoverflow
jca search "gradient boosting" --source pypi
# Show environment info
jca env
# View usage statistics
jca stats
# Configure API key and model
jca config --set-key sk-ant-your-key
jca config --set-model claude-opus-4-6
API Reference
The server extension provides a REST API at /jupyter-claude/:
POST /jupyter-claude/chat
{
"message": "How do I read a CSV file?",
"cells": [...], // Optional: notebook cells for context
"current_cell": 3, // Optional: index of active cell
"env_name": "myenv" // Optional: conda environment name
}
POST /jupyter-claude/complete
{
"code": "import pandas as pd\ndf = pd.read_",
"mode": "complete", // or "next_cell"
"goal": "optional goal description",
"cells": [...]
}
POST /jupyter-claude/assignment
{
"problem": "Build a machine learning pipeline that...",
"output_format": "cells", // or "markdown"
"env_name": "myenv",
"cells": [...]
}
POST /jupyter-claude/explain
{
"code": "df.groupby('col').agg({'val': 'mean'})",
"output": "Optional output text",
"error": "Optional error message"
}
POST /jupyter-claude/fix
{
"code": "df.groupby('col').agger({'val': 'mean'})",
"error": "AttributeError: 'DataFrameGroupBy' object has no attribute 'agger'",
"cells": [...]
}
GET /jupyter-claude/conda
Returns active conda environment, all environments, and installed packages.
GET /jupyter-claude/search?q=QUERY&source=all
Search PyPI, GitHub, and Stack Overflow. source can be all, pypi, github, stackoverflow.
GET /jupyter-claude/memory?type=stats
Get usage statistics, skills, recent interactions. type can be stats, skills, recent, snippets.
POST /jupyter-claude/memory
Save skills, snippets, ratings, and preferences.
GET/POST /jupyter-claude/config
Get or set extension configuration (API key, model).
Architecture
jupyter-claude-assistant/
โโโ jupyter_claude_assistant/ # Python server extension
โ โโโ __init__.py # Extension entry points
โ โโโ _version.py
โ โโโ extension.py # Handler registration
โ โโโ widget.py # ipywidgets-based UI
โ โโโ handlers/ # Tornado REST handlers
โ โ โโโ base_handler.py # Shared base (APIHandler + services)
โ โ โโโ chat_handler.py
โ โ โโโ complete_handler.py
โ โ โโโ explain_handler.py
โ โ โโโ fix_handler.py
โ โ โโโ assign_handler.py
โ โ โโโ conda_handler.py
โ โ โโโ memory_handler.py
โ โ โโโ search_handler.py
โ โ โโโ config_handler.py
โ โโโ services/ # Core services
โ โโโ claude_service.py # Anthropic API wrapper
โ โโโ conda_service.py # Conda environment detection
โ โโโ memory_service.py # SQLite persistence
โ โโโ search_service.py # PyPI/GitHub/SO search
โโโ cli/
โ โโโ jca.py # Click-based CLI tool
โโโ frontend/
โ โโโ src/panel.html # Standalone HTML panel UI
โโโ tests/
โโโ test_claude_service.py
โโโ test_conda_service.py
โโโ test_memory_service.py
Component Overview
-
ClaudeService: Wraps the Anthropic Python SDK. Builds notebook context from cells, handles all prompt engineering, and exposes high-level methods (
complete,explain_code,suggest_fix,complete_assignment). -
CondaService: Detects the active conda environment via
CONDA_PREFIXenvironment variables andconda env list --json. Caches package lists for performance. -
MemoryService: SQLite database at
~/.jupyter_claude/memory.db. Stores interactions with ratings, reusable skills/code patterns, snippet library, search result cache, and user preferences. Improves suggestions over time. -
SearchService: Fetches from PyPI JSON API, GitHub Search API (repos), and Stack Exchange API (Stack Overflow). Results are cached in the MemoryService.
Configuration
The assistant reads configuration from (in order of priority):
ANTHROPIC_API_KEYenvironment variable~/.jupyter_claude/config.json- JupyterLab settings (via
/jupyter-claude/configendpoint)
Available Models
| Model | ID | Best For |
|---|---|---|
| Claude Sonnet 4.6 | claude-sonnet-4-6 |
Default โ best balance of speed and quality |
| Claude Opus 4.6 | claude-opus-4-6 |
Complex problems, assignments |
| Claude Haiku 4.5 | claude-haiku-4-5-20251001 |
Quick completions, high throughput |
Memory Database
The local skills database is stored at ~/.jupyter_claude/memory.db. It contains:
- Interactions: Every request/response pair with timestamps and optional ratings
- Skills: Saved code patterns with tags (e.g., "pandas pivot table", "sklearn pipeline")
- Snippets: Saved code snippets organized by tag and conda environment
- Search Cache: Cached PyPI/GitHub/SO results (default 1-hour TTL)
- Preferences: Model selection, display preferences, etc.
Development
Running Tests
# Install dev dependencies
pip install -e ".[dev]"
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_memory_service.py -v
Adding Custom Features
To add a new endpoint:
- Create
jupyter_claude_assistant/handlers/my_handler.pyextendingBaseClaudeHandler - Add the handler to
extension.py'ssetup_handlers()function - Add corresponding method to
ClaudeServiceif needed
License
MIT License. See LICENSE for details.
Acknowledgments
- Built with Anthropic Claude API
- Extends JupyterLab server extension framework
- CLI powered by Click and Rich
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 jupyter_claude_assistant-1.0.1.tar.gz.
File metadata
- Download URL: jupyter_claude_assistant-1.0.1.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
723cc4ac2b9e7d571fcfeb358ef8014fb9958953ca06afd58f3d11fcda8ddf84
|
|
| MD5 |
1f3f025f81d9bbec2585324ae8878f8c
|
|
| BLAKE2b-256 |
9df57495df78dafd4e941bb420cc02db16b8157893c8638d6fe0e704d5d67333
|
File details
Details for the file jupyter_claude_assistant-1.0.1-py3-none-any.whl.
File metadata
- Download URL: jupyter_claude_assistant-1.0.1-py3-none-any.whl
- Upload date:
- Size: 39.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b392625af249d716c9419f2199bad4d470b16276c438c2906bf3240d5a99afb1
|
|
| MD5 |
2ae07a4411f7c08098bfdc0422ec8f2b
|
|
| BLAKE2b-256 |
1cc010479f2a76a1a16fc817903a23b9780c84a2e1701d4fafc23ac53a419d41
|