notebookllm 1.0.0__tar.gz → 2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,277 @@
1
+ Metadata-Version: 2.4
2
+ Name: notebookllm
3
+ Version: 2.0
4
+ Summary: Convert Jupyter notebooks to/from plain text for LLMs, and expose functionality via an MCP server.
5
+ Author-email: Yasir Raza <yasirabdali6@gmail.com>
6
+ Keywords: jupyter,notebook,llm,conversion,mcp,cli
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: nbformat
10
+ Requires-Dist: jupyter_client
11
+ Requires-Dist: mcp[cli]
12
+
13
+ # notebookllm
14
+
15
+ A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs).
16
+
17
+ ## Why this package?
18
+
19
+ Current Large Language Models (LLMs) cannot directly read or process `.ipynb` files. This package provides a solution by converting `.ipynb` files to a simplified plain text format that LLMs can easily understand. It also allows converting Python files to `.ipynb` files.
20
+
21
+ ## Features
22
+
23
+ - Convert `.ipynb` files to a simplified plain text (.py, .txt or .r file) format.
24
+ - Convert Python or R (.py, .txt or .r files) to `.ipynb` files.
25
+ - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using `# %% [code]` and `# %% [markdown]` identifiers.
26
+ - The plain text (.py, .txt or .r) format can be easily parsed back into a `.ipynb` file.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install notebookllm
32
+ ```
33
+ or
34
+
35
+ ```bash
36
+ git clone https://github.com/yasirrazaa/notebookllm.git
37
+ cd notebookllm
38
+ pip install .
39
+ ```
40
+
41
+ ## Usage
42
+ ## CLI
43
+
44
+ ### `to_text`
45
+
46
+ Converts a `.ipynb` file to a simplified plain text format.
47
+
48
+ Usage:
49
+
50
+ ```bash
51
+ notebookllm to_text <ipynb_file> --output <output_file>
52
+ ```
53
+
54
+ - `<ipynb_file>`: Path to the `.ipynb` file.
55
+ - `--output <output_file>`: Path to save the plain text output. If not provided, the output will be printed to the console.
56
+
57
+ Example:
58
+
59
+ ```bash
60
+ notebookllm to_text my_notebook.ipynb --output my_notebook.txt
61
+ ```
62
+
63
+ ### `to_ipynb`
64
+
65
+ Converts a `.py` file to a `.ipynb` file.
66
+
67
+ Usage:
68
+
69
+ ```bash
70
+ notebookllm to_ipynb <py_file> --output <output_file>
71
+ ```
72
+
73
+ - `<py_file>`: Path to the `.py` file.
74
+ - `--output <output_file>`: Path to save the `.ipynb` output. If not provided, the output will be saved to `output.ipynb`.
75
+
76
+ Example:
77
+
78
+ ```bash
79
+ notebookllm to_ipynb my_script.py --output my_notebook.ipynb
80
+ ```
81
+
82
+ ## API
83
+
84
+ ```python
85
+ from notebookllm import Notebook
86
+
87
+ notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
88
+ notebook.add_code_cell('print("Hello, world!")') # Add a code cell
89
+ notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
90
+ notebook.execute_cell(0) # Execute a cell
91
+ notebook.delete_cell(1) # Delete a cell
92
+ notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
93
+ notebook.save('new_notebook.ipynb') # Save the notebook
94
+ notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
95
+ notebook.save() # Save the changes
96
+ ````
97
+
98
+ ## Using `notebookllm` as an MCP Server
99
+
100
+ The `notebookllm` package includes an MCP (Model Context Protocol) server (`mcp_server.py`) that exposes notebook conversion and manipulation functionalities as tools for Large Language Models (LLMs). This allows LLMs to programmatically interact with Jupyter notebooks in a way that is token-efficient, cost-effective, and fast by focusing on plain text representations of notebook content rather than full, verbose notebook metadata.
101
+
102
+ ### Installation & Running the Server
103
+
104
+ Here’s how to install and run the `notebookllm` MCP server:
105
+
106
+ **1. Using `uvx` (Recommended for quick use)**
107
+
108
+ `uvx` allows you to run the server directly from its PyPI package without needing to install it into your global or project Python environment. This is ideal for quickly using the server with clients like Claude Desktop or VS Code.
109
+
110
+ * To run the server (assuming `notebookllm` is published to PyPI and provides a `notebookllm-server` command):
111
+ ```bash
112
+ uvx notebookllm-server
113
+ ```
114
+
115
+ **2. Using `pip` (Traditional installation)**
116
+
117
+ * Install the package from PyPI:
118
+ ```bash
119
+ pip install notebookllm
120
+ ```
121
+ * Run the server using the installed command:
122
+ ```bash
123
+ notebookllm-server
124
+ ```
125
+ *(If the package installs `mcp_server.py` as a module within the `notebookllm` package but doesn't define a direct `notebookllm-server` script, you might run it as `python -m notebookllm.mcp_server`.)*
126
+
127
+ ### Configuration with Clients
128
+
129
+ Once the server can be run using one of the methods above, you can configure various clients to use its tools.
130
+
131
+ **A. Claude Desktop**
132
+
133
+ Add the following to your `claude_desktop_config.json` file (typically found at `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, or `%APPDATA%\Claude\claude_desktop_config.json` on Windows):
134
+
135
+ * **Using `uvx`:**
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "notebookllm": {
140
+ "command": "uvx",
141
+ "args": ["notebookllm-server"]
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ * **Using `pip` installation:**
148
+ ```json
149
+ {
150
+ "mcpServers": {
151
+ "notebookllm": {
152
+ "command": "notebookllm-server", // Or full path if not in PATH, or 'python'
153
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ **B. VS Code**
160
+
161
+ Add the following to your User Settings (JSON) file (`Ctrl + Shift + P` -> "Preferences: Open User Settings (JSON)") or to a `.vscode/mcp.json` file in your workspace (if using `.vscode/mcp.json`, omit the top-level `"mcp": { ... }` wrapper).
162
+
163
+ * **Using `uvx`:**
164
+ ```json
165
+ {
166
+ "mcp": {
167
+ "servers": {
168
+ "notebookllm": {
169
+ "command": "uvx",
170
+ "args": ["notebookllm-server"]
171
+ }
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ * **Using `pip` installation:**
178
+ ```json
179
+ {
180
+ "mcp": {
181
+ "servers": {
182
+ "notebookllm": {
183
+ "command": "notebookllm-server", // Or 'python'
184
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
185
+ }
186
+ }
187
+ }
188
+ }
189
+ ```
190
+
191
+ **C. Zed Editor**
192
+
193
+ Add the following to your Zed `settings.json` (accessible via `Zed > Settings > Open Settings (JSON)`):
194
+
195
+ * **Using `uvx`:**
196
+ ```json
197
+ {
198
+ "mcp_servers": {
199
+ "notebookllm": {
200
+ "command": "uvx",
201
+ "args": ["notebookllm-server"]
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ * **Using `pip` installation:**
208
+ ```json
209
+ {
210
+ "mcp_servers": {
211
+ "notebookllm": {
212
+ "command": "notebookllm-server", // Or 'python'
213
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ ### Available Tools
220
+
221
+ The MCP server exposes the following tools (refer to the `mcp_server.py` file within the `notebookllm` package for detailed descriptions and parameters):
222
+
223
+ * `load_notebook(filepath: str)`: Loads a `.ipynb` file into memory for efficient operations.
224
+ * `notebook_to_plain_text(input_filepath: str | None = None)`: Converts a notebook to token-efficient plain text.
225
+ * `plain_text_to_notebook_file(plain_text_content: str, output_filepath: str)`: Converts plain text back to a `.ipynb` file.
226
+ * `add_code_cell_to_loaded_notebook(code_content: str, position: int | None = None)`: Adds a code cell to the loaded notebook.
227
+ * `add_markdown_cell_to_loaded_notebook(markdown_content: str, position: int | None = None)`: Adds a markdown cell to the loaded notebook.
228
+ * `save_loaded_notebook(output_filepath: str | None = None)`: Saves the loaded notebook.
229
+
230
+ ### Debugging the Server
231
+
232
+ You can use the MCP Inspector to debug the server.
233
+
234
+ * **If using `uvx`:**
235
+ ```bash
236
+ npx @modelcontextprotocol/inspector uvx notebookllm-server
237
+ ```
238
+
239
+ * **If using a `pip` installed version (assuming `notebookllm-server` is the command):**
240
+ ```bash
241
+ npx @modelcontextprotocol/inspector notebookllm-server
242
+ ```
243
+ *(If running as a module: `npx @modelcontextprotocol/inspector python -m notebookllm.mcp_server`)*
244
+
245
+ Check the logs from your client application (e.g., Claude Desktop logs typically found in `~/Library/Logs/Claude/mcp*.log` on macOS or `%APPDATA%\Claude\mcp*.log` on Windows) for more detailed error messages from the server.
246
+
247
+ ### Development & Local Testing
248
+
249
+ If you are developing `notebookllm` locally:
250
+
251
+ 1. **Clone the repository:**
252
+ ```bash
253
+ git clone https://github.com/yasirrazaa/notebookllm.git # Or your fork
254
+ cd notebookllm
255
+ ```
256
+ 2. **Set up the environment using `uv`:**
257
+ ```bash
258
+ uv init # If not already done for this project
259
+ uv sync # Installs dependencies from pyproject.toml, including mcp[cli]
260
+ uv pip install -e . # Installs the notebookllm package in editable mode
261
+ ```
262
+ 3. **Run the local server for testing:**
263
+ * Using `mcp dev` for the MCP Inspector (recommended for interactive testing):
264
+ ```bash
265
+ uv run mcp dev mcp_server.py
266
+ ```
267
+ * Running the local `mcp_server.py` script directly:
268
+ ```bash
269
+ uv run python mcp_server.py
270
+ ```
271
+ * If you've installed in editable mode and defined the `notebookllm-server` script in your `pyproject.toml`, you can also test it as if it were installed:
272
+ ```bash
273
+ uv run notebookllm-server
274
+ ```
275
+
276
+ By providing these tools via MCP, `notebookllm` empowers LLMs to become more active participants in the notebook development and manipulation workflow, enhancing productivity and reducing manual effort by focusing on cost-effective, token-efficient operations.
277
+
@@ -0,0 +1,265 @@
1
+ # notebookllm
2
+
3
+ A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs).
4
+
5
+ ## Why this package?
6
+
7
+ Current Large Language Models (LLMs) cannot directly read or process `.ipynb` files. This package provides a solution by converting `.ipynb` files to a simplified plain text format that LLMs can easily understand. It also allows converting Python files to `.ipynb` files.
8
+
9
+ ## Features
10
+
11
+ - Convert `.ipynb` files to a simplified plain text (.py, .txt or .r file) format.
12
+ - Convert Python or R (.py, .txt or .r files) to `.ipynb` files.
13
+ - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using `# %% [code]` and `# %% [markdown]` identifiers.
14
+ - The plain text (.py, .txt or .r) format can be easily parsed back into a `.ipynb` file.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install notebookllm
20
+ ```
21
+ or
22
+
23
+ ```bash
24
+ git clone https://github.com/yasirrazaa/notebookllm.git
25
+ cd notebookllm
26
+ pip install .
27
+ ```
28
+
29
+ ## Usage
30
+ ## CLI
31
+
32
+ ### `to_text`
33
+
34
+ Converts a `.ipynb` file to a simplified plain text format.
35
+
36
+ Usage:
37
+
38
+ ```bash
39
+ notebookllm to_text <ipynb_file> --output <output_file>
40
+ ```
41
+
42
+ - `<ipynb_file>`: Path to the `.ipynb` file.
43
+ - `--output <output_file>`: Path to save the plain text output. If not provided, the output will be printed to the console.
44
+
45
+ Example:
46
+
47
+ ```bash
48
+ notebookllm to_text my_notebook.ipynb --output my_notebook.txt
49
+ ```
50
+
51
+ ### `to_ipynb`
52
+
53
+ Converts a `.py` file to a `.ipynb` file.
54
+
55
+ Usage:
56
+
57
+ ```bash
58
+ notebookllm to_ipynb <py_file> --output <output_file>
59
+ ```
60
+
61
+ - `<py_file>`: Path to the `.py` file.
62
+ - `--output <output_file>`: Path to save the `.ipynb` output. If not provided, the output will be saved to `output.ipynb`.
63
+
64
+ Example:
65
+
66
+ ```bash
67
+ notebookllm to_ipynb my_script.py --output my_notebook.ipynb
68
+ ```
69
+
70
+ ## API
71
+
72
+ ```python
73
+ from notebookllm import Notebook
74
+
75
+ notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
76
+ notebook.add_code_cell('print("Hello, world!")') # Add a code cell
77
+ notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
78
+ notebook.execute_cell(0) # Execute a cell
79
+ notebook.delete_cell(1) # Delete a cell
80
+ notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
81
+ notebook.save('new_notebook.ipynb') # Save the notebook
82
+ notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
83
+ notebook.save() # Save the changes
84
+ ````
85
+
86
+ ## Using `notebookllm` as an MCP Server
87
+
88
+ The `notebookllm` package includes an MCP (Model Context Protocol) server (`mcp_server.py`) that exposes notebook conversion and manipulation functionalities as tools for Large Language Models (LLMs). This allows LLMs to programmatically interact with Jupyter notebooks in a way that is token-efficient, cost-effective, and fast by focusing on plain text representations of notebook content rather than full, verbose notebook metadata.
89
+
90
+ ### Installation & Running the Server
91
+
92
+ Here’s how to install and run the `notebookllm` MCP server:
93
+
94
+ **1. Using `uvx` (Recommended for quick use)**
95
+
96
+ `uvx` allows you to run the server directly from its PyPI package without needing to install it into your global or project Python environment. This is ideal for quickly using the server with clients like Claude Desktop or VS Code.
97
+
98
+ * To run the server (assuming `notebookllm` is published to PyPI and provides a `notebookllm-server` command):
99
+ ```bash
100
+ uvx notebookllm-server
101
+ ```
102
+
103
+ **2. Using `pip` (Traditional installation)**
104
+
105
+ * Install the package from PyPI:
106
+ ```bash
107
+ pip install notebookllm
108
+ ```
109
+ * Run the server using the installed command:
110
+ ```bash
111
+ notebookllm-server
112
+ ```
113
+ *(If the package installs `mcp_server.py` as a module within the `notebookllm` package but doesn't define a direct `notebookllm-server` script, you might run it as `python -m notebookllm.mcp_server`.)*
114
+
115
+ ### Configuration with Clients
116
+
117
+ Once the server can be run using one of the methods above, you can configure various clients to use its tools.
118
+
119
+ **A. Claude Desktop**
120
+
121
+ Add the following to your `claude_desktop_config.json` file (typically found at `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, or `%APPDATA%\Claude\claude_desktop_config.json` on Windows):
122
+
123
+ * **Using `uvx`:**
124
+ ```json
125
+ {
126
+ "mcpServers": {
127
+ "notebookllm": {
128
+ "command": "uvx",
129
+ "args": ["notebookllm-server"]
130
+ }
131
+ }
132
+ }
133
+ ```
134
+
135
+ * **Using `pip` installation:**
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "notebookllm": {
140
+ "command": "notebookllm-server", // Or full path if not in PATH, or 'python'
141
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ **B. VS Code**
148
+
149
+ Add the following to your User Settings (JSON) file (`Ctrl + Shift + P` -> "Preferences: Open User Settings (JSON)") or to a `.vscode/mcp.json` file in your workspace (if using `.vscode/mcp.json`, omit the top-level `"mcp": { ... }` wrapper).
150
+
151
+ * **Using `uvx`:**
152
+ ```json
153
+ {
154
+ "mcp": {
155
+ "servers": {
156
+ "notebookllm": {
157
+ "command": "uvx",
158
+ "args": ["notebookllm-server"]
159
+ }
160
+ }
161
+ }
162
+ }
163
+ ```
164
+
165
+ * **Using `pip` installation:**
166
+ ```json
167
+ {
168
+ "mcp": {
169
+ "servers": {
170
+ "notebookllm": {
171
+ "command": "notebookllm-server", // Or 'python'
172
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
173
+ }
174
+ }
175
+ }
176
+ }
177
+ ```
178
+
179
+ **C. Zed Editor**
180
+
181
+ Add the following to your Zed `settings.json` (accessible via `Zed > Settings > Open Settings (JSON)`):
182
+
183
+ * **Using `uvx`:**
184
+ ```json
185
+ {
186
+ "mcp_servers": {
187
+ "notebookllm": {
188
+ "command": "uvx",
189
+ "args": ["notebookllm-server"]
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ * **Using `pip` installation:**
196
+ ```json
197
+ {
198
+ "mcp_servers": {
199
+ "notebookllm": {
200
+ "command": "notebookllm-server", // Or 'python'
201
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ ### Available Tools
208
+
209
+ The MCP server exposes the following tools (refer to the `mcp_server.py` file within the `notebookllm` package for detailed descriptions and parameters):
210
+
211
+ * `load_notebook(filepath: str)`: Loads a `.ipynb` file into memory for efficient operations.
212
+ * `notebook_to_plain_text(input_filepath: str | None = None)`: Converts a notebook to token-efficient plain text.
213
+ * `plain_text_to_notebook_file(plain_text_content: str, output_filepath: str)`: Converts plain text back to a `.ipynb` file.
214
+ * `add_code_cell_to_loaded_notebook(code_content: str, position: int | None = None)`: Adds a code cell to the loaded notebook.
215
+ * `add_markdown_cell_to_loaded_notebook(markdown_content: str, position: int | None = None)`: Adds a markdown cell to the loaded notebook.
216
+ * `save_loaded_notebook(output_filepath: str | None = None)`: Saves the loaded notebook.
217
+
218
+ ### Debugging the Server
219
+
220
+ You can use the MCP Inspector to debug the server.
221
+
222
+ * **If using `uvx`:**
223
+ ```bash
224
+ npx @modelcontextprotocol/inspector uvx notebookllm-server
225
+ ```
226
+
227
+ * **If using a `pip` installed version (assuming `notebookllm-server` is the command):**
228
+ ```bash
229
+ npx @modelcontextprotocol/inspector notebookllm-server
230
+ ```
231
+ *(If running as a module: `npx @modelcontextprotocol/inspector python -m notebookllm.mcp_server`)*
232
+
233
+ Check the logs from your client application (e.g., Claude Desktop logs typically found in `~/Library/Logs/Claude/mcp*.log` on macOS or `%APPDATA%\Claude\mcp*.log` on Windows) for more detailed error messages from the server.
234
+
235
+ ### Development & Local Testing
236
+
237
+ If you are developing `notebookllm` locally:
238
+
239
+ 1. **Clone the repository:**
240
+ ```bash
241
+ git clone https://github.com/yasirrazaa/notebookllm.git # Or your fork
242
+ cd notebookllm
243
+ ```
244
+ 2. **Set up the environment using `uv`:**
245
+ ```bash
246
+ uv init # If not already done for this project
247
+ uv sync # Installs dependencies from pyproject.toml, including mcp[cli]
248
+ uv pip install -e . # Installs the notebookllm package in editable mode
249
+ ```
250
+ 3. **Run the local server for testing:**
251
+ * Using `mcp dev` for the MCP Inspector (recommended for interactive testing):
252
+ ```bash
253
+ uv run mcp dev mcp_server.py
254
+ ```
255
+ * Running the local `mcp_server.py` script directly:
256
+ ```bash
257
+ uv run python mcp_server.py
258
+ ```
259
+ * If you've installed in editable mode and defined the `notebookllm-server` script in your `pyproject.toml`, you can also test it as if it were installed:
260
+ ```bash
261
+ uv run notebookllm-server
262
+ ```
263
+
264
+ By providing these tools via MCP, `notebookllm` empowers LLMs to become more active participants in the notebook development and manipulation workflow, enhancing productivity and reducing manual effort by focusing on cost-effective, token-efficient operations.
265
+
@@ -0,0 +1,277 @@
1
+ Metadata-Version: 2.4
2
+ Name: notebookllm
3
+ Version: 2.0
4
+ Summary: Convert Jupyter notebooks to/from plain text for LLMs, and expose functionality via an MCP server.
5
+ Author-email: Yasir Raza <yasirabdali6@gmail.com>
6
+ Keywords: jupyter,notebook,llm,conversion,mcp,cli
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: nbformat
10
+ Requires-Dist: jupyter_client
11
+ Requires-Dist: mcp[cli]
12
+
13
+ # notebookllm
14
+
15
+ A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs).
16
+
17
+ ## Why this package?
18
+
19
+ Current Large Language Models (LLMs) cannot directly read or process `.ipynb` files. This package provides a solution by converting `.ipynb` files to a simplified plain text format that LLMs can easily understand. It also allows converting Python files to `.ipynb` files.
20
+
21
+ ## Features
22
+
23
+ - Convert `.ipynb` files to a simplified plain text (.py, .txt or .r file) format.
24
+ - Convert Python or R (.py, .txt or .r files) to `.ipynb` files.
25
+ - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using `# %% [code]` and `# %% [markdown]` identifiers.
26
+ - The plain text (.py, .txt or .r) format can be easily parsed back into a `.ipynb` file.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install notebookllm
32
+ ```
33
+ or
34
+
35
+ ```bash
36
+ git clone https://github.com/yasirrazaa/notebookllm.git
37
+ cd notebookllm
38
+ pip install .
39
+ ```
40
+
41
+ ## Usage
42
+ ## CLI
43
+
44
+ ### `to_text`
45
+
46
+ Converts a `.ipynb` file to a simplified plain text format.
47
+
48
+ Usage:
49
+
50
+ ```bash
51
+ notebookllm to_text <ipynb_file> --output <output_file>
52
+ ```
53
+
54
+ - `<ipynb_file>`: Path to the `.ipynb` file.
55
+ - `--output <output_file>`: Path to save the plain text output. If not provided, the output will be printed to the console.
56
+
57
+ Example:
58
+
59
+ ```bash
60
+ notebookllm to_text my_notebook.ipynb --output my_notebook.txt
61
+ ```
62
+
63
+ ### `to_ipynb`
64
+
65
+ Converts a `.py` file to a `.ipynb` file.
66
+
67
+ Usage:
68
+
69
+ ```bash
70
+ notebookllm to_ipynb <py_file> --output <output_file>
71
+ ```
72
+
73
+ - `<py_file>`: Path to the `.py` file.
74
+ - `--output <output_file>`: Path to save the `.ipynb` output. If not provided, the output will be saved to `output.ipynb`.
75
+
76
+ Example:
77
+
78
+ ```bash
79
+ notebookllm to_ipynb my_script.py --output my_notebook.ipynb
80
+ ```
81
+
82
+ ## API
83
+
84
+ ```python
85
+ from notebookllm import Notebook
86
+
87
+ notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
88
+ notebook.add_code_cell('print("Hello, world!")') # Add a code cell
89
+ notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
90
+ notebook.execute_cell(0) # Execute a cell
91
+ notebook.delete_cell(1) # Delete a cell
92
+ notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
93
+ notebook.save('new_notebook.ipynb') # Save the notebook
94
+ notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
95
+ notebook.save() # Save the changes
96
+ ````
97
+
98
+ ## Using `notebookllm` as an MCP Server
99
+
100
+ The `notebookllm` package includes an MCP (Model Context Protocol) server (`mcp_server.py`) that exposes notebook conversion and manipulation functionalities as tools for Large Language Models (LLMs). This allows LLMs to programmatically interact with Jupyter notebooks in a way that is token-efficient, cost-effective, and fast by focusing on plain text representations of notebook content rather than full, verbose notebook metadata.
101
+
102
+ ### Installation & Running the Server
103
+
104
+ Here’s how to install and run the `notebookllm` MCP server:
105
+
106
+ **1. Using `uvx` (Recommended for quick use)**
107
+
108
+ `uvx` allows you to run the server directly from its PyPI package without needing to install it into your global or project Python environment. This is ideal for quickly using the server with clients like Claude Desktop or VS Code.
109
+
110
+ * To run the server (assuming `notebookllm` is published to PyPI and provides a `notebookllm-server` command):
111
+ ```bash
112
+ uvx notebookllm-server
113
+ ```
114
+
115
+ **2. Using `pip` (Traditional installation)**
116
+
117
+ * Install the package from PyPI:
118
+ ```bash
119
+ pip install notebookllm
120
+ ```
121
+ * Run the server using the installed command:
122
+ ```bash
123
+ notebookllm-server
124
+ ```
125
+ *(If the package installs `mcp_server.py` as a module within the `notebookllm` package but doesn't define a direct `notebookllm-server` script, you might run it as `python -m notebookllm.mcp_server`.)*
126
+
127
+ ### Configuration with Clients
128
+
129
+ Once the server can be run using one of the methods above, you can configure various clients to use its tools.
130
+
131
+ **A. Claude Desktop**
132
+
133
+ Add the following to your `claude_desktop_config.json` file (typically found at `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, or `%APPDATA%\Claude\claude_desktop_config.json` on Windows):
134
+
135
+ * **Using `uvx`:**
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "notebookllm": {
140
+ "command": "uvx",
141
+ "args": ["notebookllm-server"]
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ * **Using `pip` installation:**
148
+ ```json
149
+ {
150
+ "mcpServers": {
151
+ "notebookllm": {
152
+ "command": "notebookllm-server", // Or full path if not in PATH, or 'python'
153
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ **B. VS Code**
160
+
161
+ Add the following to your User Settings (JSON) file (`Ctrl + Shift + P` -> "Preferences: Open User Settings (JSON)") or to a `.vscode/mcp.json` file in your workspace (if using `.vscode/mcp.json`, omit the top-level `"mcp": { ... }` wrapper).
162
+
163
+ * **Using `uvx`:**
164
+ ```json
165
+ {
166
+ "mcp": {
167
+ "servers": {
168
+ "notebookllm": {
169
+ "command": "uvx",
170
+ "args": ["notebookllm-server"]
171
+ }
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ * **Using `pip` installation:**
178
+ ```json
179
+ {
180
+ "mcp": {
181
+ "servers": {
182
+ "notebookllm": {
183
+ "command": "notebookllm-server", // Or 'python'
184
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
185
+ }
186
+ }
187
+ }
188
+ }
189
+ ```
190
+
191
+ **C. Zed Editor**
192
+
193
+ Add the following to your Zed `settings.json` (accessible via `Zed > Settings > Open Settings (JSON)`):
194
+
195
+ * **Using `uvx`:**
196
+ ```json
197
+ {
198
+ "mcp_servers": {
199
+ "notebookllm": {
200
+ "command": "uvx",
201
+ "args": ["notebookllm-server"]
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ * **Using `pip` installation:**
208
+ ```json
209
+ {
210
+ "mcp_servers": {
211
+ "notebookllm": {
212
+ "command": "notebookllm-server", // Or 'python'
213
+ "args": [] // If using 'python', args would be ['-m', 'notebookllm.mcp_server']
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ ### Available Tools
220
+
221
+ The MCP server exposes the following tools (refer to the `mcp_server.py` file within the `notebookllm` package for detailed descriptions and parameters):
222
+
223
+ * `load_notebook(filepath: str)`: Loads a `.ipynb` file into memory for efficient operations.
224
+ * `notebook_to_plain_text(input_filepath: str | None = None)`: Converts a notebook to token-efficient plain text.
225
+ * `plain_text_to_notebook_file(plain_text_content: str, output_filepath: str)`: Converts plain text back to a `.ipynb` file.
226
+ * `add_code_cell_to_loaded_notebook(code_content: str, position: int | None = None)`: Adds a code cell to the loaded notebook.
227
+ * `add_markdown_cell_to_loaded_notebook(markdown_content: str, position: int | None = None)`: Adds a markdown cell to the loaded notebook.
228
+ * `save_loaded_notebook(output_filepath: str | None = None)`: Saves the loaded notebook.
229
+
230
+ ### Debugging the Server
231
+
232
+ You can use the MCP Inspector to debug the server.
233
+
234
+ * **If using `uvx`:**
235
+ ```bash
236
+ npx @modelcontextprotocol/inspector uvx notebookllm-server
237
+ ```
238
+
239
+ * **If using a `pip` installed version (assuming `notebookllm-server` is the command):**
240
+ ```bash
241
+ npx @modelcontextprotocol/inspector notebookllm-server
242
+ ```
243
+ *(If running as a module: `npx @modelcontextprotocol/inspector python -m notebookllm.mcp_server`)*
244
+
245
+ Check the logs from your client application (e.g., Claude Desktop logs typically found in `~/Library/Logs/Claude/mcp*.log` on macOS or `%APPDATA%\Claude\mcp*.log` on Windows) for more detailed error messages from the server.
246
+
247
+ ### Development & Local Testing
248
+
249
+ If you are developing `notebookllm` locally:
250
+
251
+ 1. **Clone the repository:**
252
+ ```bash
253
+ git clone https://github.com/yasirrazaa/notebookllm.git # Or your fork
254
+ cd notebookllm
255
+ ```
256
+ 2. **Set up the environment using `uv`:**
257
+ ```bash
258
+ uv init # If not already done for this project
259
+ uv sync # Installs dependencies from pyproject.toml, including mcp[cli]
260
+ uv pip install -e . # Installs the notebookllm package in editable mode
261
+ ```
262
+ 3. **Run the local server for testing:**
263
+ * Using `mcp dev` for the MCP Inspector (recommended for interactive testing):
264
+ ```bash
265
+ uv run mcp dev mcp_server.py
266
+ ```
267
+ * Running the local `mcp_server.py` script directly:
268
+ ```bash
269
+ uv run python mcp_server.py
270
+ ```
271
+ * If you've installed in editable mode and defined the `notebookllm-server` script in your `pyproject.toml`, you can also test it as if it were installed:
272
+ ```bash
273
+ uv run notebookllm-server
274
+ ```
275
+
276
+ By providing these tools via MCP, `notebookllm` empowers LLMs to become more active participants in the notebook development and manipulation workflow, enhancing productivity and reducing manual effort by focusing on cost-effective, token-efficient operations.
277
+
@@ -1,7 +1,6 @@
1
1
  README.md
2
2
  cli.py
3
3
  pyproject.toml
4
- setup.py
5
4
  notebookllm/__init__.py
6
5
  notebookllm/notebookllm.py
7
6
  notebookllm.egg-info/PKG-INFO
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
2
  notebookllm = cli:main
3
+ notebookllm-server = mcp_server:main_cli
@@ -1,2 +1,3 @@
1
1
  nbformat
2
2
  jupyter_client
3
+ mcp[cli]
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+ backend-path = ["."] # Ensures setuptools can find local configurations if needed
5
+
6
+ [project]
7
+ name = "notebookllm"
8
+ version = "2.0"
9
+ description = "Convert Jupyter notebooks to/from plain text for LLMs, and expose functionality via an MCP server."
10
+ readme = "README.md"
11
+ requires-python = ">=3.10" # You can adjust this if needed
12
+ license = { file = "LICENSE" } # Consider creating a LICENSE file (e.g., MIT)
13
+ authors = [
14
+ { name = "Yasir Raza", email = "yasirabdali6@gmail.com" }
15
+ ]
16
+ keywords = ["jupyter", "notebook", "llm", "conversion", "mcp", "cli"]
17
+
18
+ dependencies = [
19
+ "nbformat",
20
+ "jupyter_client",
21
+ "mcp[cli]"
22
+ ]
23
+
24
+ [project.scripts]
25
+ notebookllm = "cli:main"
26
+ notebookllm-server = "mcp_server:main_cli"
27
+
28
+ # Optional: If you want to be more explicit about package discovery for setuptools
notebookllm-1.0/PKG-INFO DELETED
@@ -1,91 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: notebookllm
3
- Version: 1.0
4
- Description-Content-Type: text/markdown
5
- Requires-Dist: nbformat
6
- Requires-Dist: jupyter_client
7
-
8
- # notebookllm
9
-
10
- A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs).
11
-
12
- ## Why this package?
13
-
14
- Current Large Language Models (LLMs) cannot directly read or process `.ipynb` files. This package provides a solution by converting `.ipynb` files to a simplified plain text format that LLMs can easily understand. It also allows converting Python files to `.ipynb` files.
15
-
16
- ## Features
17
-
18
- - Convert `.ipynb` files to a simplified plain text (.py, .txt or .r file) format.
19
- - Convert Python or R (.py, .txt or .r files) to `.ipynb` files.
20
- - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using `# %% [code]` and `# %% [markdown]` identifiers.
21
- - The plain text (.py, .txt or .r) format can be easily parsed back into a `.ipynb` file.
22
-
23
- ## Installation
24
-
25
- ```bash
26
- pip install notebookllm
27
- ```
28
- or
29
-
30
- ```bash
31
- git clone https://github.com/yasirrazaa/notebookllm.git
32
- cd notebookllm
33
- pip install .
34
- ```
35
-
36
- ## Usage
37
- ## CLI
38
-
39
- ### `to_text`
40
-
41
- Converts a `.ipynb` file to a simplified plain text format.
42
-
43
- Usage:
44
-
45
- ```bash
46
- notebookllm to_text <ipynb_file> --output <output_file>
47
- ```
48
-
49
- - `<ipynb_file>`: Path to the `.ipynb` file.
50
- - `--output <output_file>`: Path to save the plain text output. If not provided, the output will be printed to the console.
51
-
52
- Example:
53
-
54
- ```bash
55
- notebookllm to_text my_notebook.ipynb --output my_notebook.txt
56
- ```
57
-
58
- ### `to_ipynb`
59
-
60
- Converts a `.py` file to a `.ipynb` file.
61
-
62
- Usage:
63
-
64
- ```bash
65
- notebookllm to_ipynb <py_file> --output <output_file>
66
- ```
67
-
68
- - `<py_file>`: Path to the `.py` file.
69
- - `--output <output_file>`: Path to save the `.ipynb` output. If not provided, the output will be saved to `output.ipynb`.
70
-
71
- Example:
72
-
73
- ```bash
74
- notebookllm to_ipynb my_script.py --output my_notebook.ipynb
75
- ```
76
-
77
- ## API
78
-
79
- ```python
80
- from notebookllm import Notebook
81
-
82
- notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
83
- notebook.add_code_cell('print("Hello, world!")') # Add a code cell
84
- notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
85
- notebook.execute_cell(0) # Execute a cell
86
- notebook.delete_cell(1) # Delete a cell
87
- notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
88
- notebook.save('new_notebook.ipynb') # Save the notebook
89
- notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
90
- notebook.save() # Save the changes
91
-
notebookllm-1.0/README.md DELETED
@@ -1,84 +0,0 @@
1
- # notebookllm
2
-
3
- A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs).
4
-
5
- ## Why this package?
6
-
7
- Current Large Language Models (LLMs) cannot directly read or process `.ipynb` files. This package provides a solution by converting `.ipynb` files to a simplified plain text format that LLMs can easily understand. It also allows converting Python files to `.ipynb` files.
8
-
9
- ## Features
10
-
11
- - Convert `.ipynb` files to a simplified plain text (.py, .txt or .r file) format.
12
- - Convert Python or R (.py, .txt or .r files) to `.ipynb` files.
13
- - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using `# %% [code]` and `# %% [markdown]` identifiers.
14
- - The plain text (.py, .txt or .r) format can be easily parsed back into a `.ipynb` file.
15
-
16
- ## Installation
17
-
18
- ```bash
19
- pip install notebookllm
20
- ```
21
- or
22
-
23
- ```bash
24
- git clone https://github.com/yasirrazaa/notebookllm.git
25
- cd notebookllm
26
- pip install .
27
- ```
28
-
29
- ## Usage
30
- ## CLI
31
-
32
- ### `to_text`
33
-
34
- Converts a `.ipynb` file to a simplified plain text format.
35
-
36
- Usage:
37
-
38
- ```bash
39
- notebookllm to_text <ipynb_file> --output <output_file>
40
- ```
41
-
42
- - `<ipynb_file>`: Path to the `.ipynb` file.
43
- - `--output <output_file>`: Path to save the plain text output. If not provided, the output will be printed to the console.
44
-
45
- Example:
46
-
47
- ```bash
48
- notebookllm to_text my_notebook.ipynb --output my_notebook.txt
49
- ```
50
-
51
- ### `to_ipynb`
52
-
53
- Converts a `.py` file to a `.ipynb` file.
54
-
55
- Usage:
56
-
57
- ```bash
58
- notebookllm to_ipynb <py_file> --output <output_file>
59
- ```
60
-
61
- - `<py_file>`: Path to the `.py` file.
62
- - `--output <output_file>`: Path to save the `.ipynb` output. If not provided, the output will be saved to `output.ipynb`.
63
-
64
- Example:
65
-
66
- ```bash
67
- notebookllm to_ipynb my_script.py --output my_notebook.ipynb
68
- ```
69
-
70
- ## API
71
-
72
- ```python
73
- from notebookllm import Notebook
74
-
75
- notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
76
- notebook.add_code_cell('print("Hello, world!")') # Add a code cell
77
- notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
78
- notebook.execute_cell(0) # Execute a cell
79
- notebook.delete_cell(1) # Delete a cell
80
- notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
81
- notebook.save('new_notebook.ipynb') # Save the notebook
82
- notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
83
- notebook.save() # Save the changes
84
-
@@ -1,91 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: notebookllm
3
- Version: 1.0
4
- Description-Content-Type: text/markdown
5
- Requires-Dist: nbformat
6
- Requires-Dist: jupyter_client
7
-
8
- # notebookllm
9
-
10
- A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs).
11
-
12
- ## Why this package?
13
-
14
- Current Large Language Models (LLMs) cannot directly read or process `.ipynb` files. This package provides a solution by converting `.ipynb` files to a simplified plain text format that LLMs can easily understand. It also allows converting Python files to `.ipynb` files.
15
-
16
- ## Features
17
-
18
- - Convert `.ipynb` files to a simplified plain text (.py, .txt or .r file) format.
19
- - Convert Python or R (.py, .txt or .r files) to `.ipynb` files.
20
- - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using `# %% [code]` and `# %% [markdown]` identifiers.
21
- - The plain text (.py, .txt or .r) format can be easily parsed back into a `.ipynb` file.
22
-
23
- ## Installation
24
-
25
- ```bash
26
- pip install notebookllm
27
- ```
28
- or
29
-
30
- ```bash
31
- git clone https://github.com/yasirrazaa/notebookllm.git
32
- cd notebookllm
33
- pip install .
34
- ```
35
-
36
- ## Usage
37
- ## CLI
38
-
39
- ### `to_text`
40
-
41
- Converts a `.ipynb` file to a simplified plain text format.
42
-
43
- Usage:
44
-
45
- ```bash
46
- notebookllm to_text <ipynb_file> --output <output_file>
47
- ```
48
-
49
- - `<ipynb_file>`: Path to the `.ipynb` file.
50
- - `--output <output_file>`: Path to save the plain text output. If not provided, the output will be printed to the console.
51
-
52
- Example:
53
-
54
- ```bash
55
- notebookllm to_text my_notebook.ipynb --output my_notebook.txt
56
- ```
57
-
58
- ### `to_ipynb`
59
-
60
- Converts a `.py` file to a `.ipynb` file.
61
-
62
- Usage:
63
-
64
- ```bash
65
- notebookllm to_ipynb <py_file> --output <output_file>
66
- ```
67
-
68
- - `<py_file>`: Path to the `.py` file.
69
- - `--output <output_file>`: Path to save the `.ipynb` output. If not provided, the output will be saved to `output.ipynb`.
70
-
71
- Example:
72
-
73
- ```bash
74
- notebookllm to_ipynb my_script.py --output my_notebook.ipynb
75
- ```
76
-
77
- ## API
78
-
79
- ```python
80
- from notebookllm import Notebook
81
-
82
- notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
83
- notebook.add_code_cell('print("Hello, world!")') # Add a code cell
84
- notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
85
- notebook.execute_cell(0) # Execute a cell
86
- notebook.delete_cell(1) # Delete a cell
87
- notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
88
- notebook.save('new_notebook.ipynb') # Save the notebook
89
- notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
90
- notebook.save() # Save the changes
91
-
@@ -1,3 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=43.0.0", "wheel"]
3
- build-backend = "setuptools.build_meta"
notebookllm-1.0/setup.py DELETED
@@ -1,23 +0,0 @@
1
- from setuptools import setup, find_packages
2
- import os
3
-
4
- def read(fname):
5
- return open(os.path.join(os.path.dirname(__file__), fname)).read()
6
-
7
- setup(
8
- name='notebookllm',
9
- version='1.0',
10
- packages=find_packages(),
11
- py_modules=['cli'],
12
- install_requires=[
13
- 'nbformat',
14
- 'jupyter_client',
15
- ],
16
- long_description=read('README.md'),
17
- long_description_content_type='text/markdown',
18
- entry_points={
19
- "console_scripts": [
20
- "notebookllm = cli:main",
21
- ],
22
- },
23
- )
File without changes
File without changes