A tool for converting Jupyter notebooks to interactive LLM-friendly and token efficient formats by providing CLI utilities for notebook management and processing.
Project description
notebookllm : https://pypi.org/project/notebookllm
A Python package to bridge the gap between Jupyter Notebooks and Large Language Models (LLMs). It reduces token usage,cost and makesit easy for llms to work with large notebooks by providing only the actual code omitting the cell metadata.
Why this package?
Current Large Language Models (LLMs) struggles when working with .ipynb files. Working with raw .ipynb files with LLMs often leads to heavy token usage, increased costs, and challenges with context window limitations due to the verbose JSON structure and metadata. This package provides a solution by converting .ipynb files to a simplified plain text format that LLMs can easily understand, significantly reducing token count. It also allows converting Python files back to .ipynb files.
Features
- Convert
.ipynbfiles to a simplified plain text (.py, .txt or .r file) format. - Convert Python or R (.py, .txt or .r files) to
.ipynbfiles. - The plain text (.py, .txt or .r) format preserves the structure of the notebook, including code and markdown cells, using
# %% [code]and# %% [markdown]identifiers. - The plain text (.py, .txt or .r) format can be easily parsed back into a
.ipynbfile.
Installation
pip install notebookllm
or
git clone https://github.com/yasirrazaa/notebookllm.git
cd notebookllm
pip install .
Usage
CLI
to_text
Converts a .ipynb file to a simplified plain text format.
Usage:
notebookllm to_text <ipynb_file> --output <output_file>
<ipynb_file>: Path to the.ipynbfile.--output <output_file>: Path to save the plain text output. If not provided, the output will be printed to the console.
Example:
notebookllm to_text my_notebook.ipynb --output my_notebook.txt
to_ipynb
Converts a .py file to a .ipynb file.
Usage:
notebookllm to_ipynb <py_file> --output <output_file>
<py_file>: Path to the.pyfile.--output <output_file>: Path to save the.ipynboutput. If not provided, the output will be saved tooutput.ipynb.
Example:
notebookllm to_ipynb my_script.py --output my_notebook.ipynb
API
from notebookllm import Notebook
notebook = Notebook(filepath='notebook.ipynb') # Load existing notebook or create a new one
notebook.add_code_cell('print("Hello, world!")') # Add a code cell
notebook.add_markdown_cell('# This is a markdown cell') # Add a markdown cell
notebook.execute_cell(0) # Execute a cell
notebook.delete_cell(1) # Delete a cell
notebook.add_raw_cell('{"data": {"text/plain": "This is a raw cell"}}') # Add a raw cell
notebook.save('new_notebook.ipynb') # Save the notebook
notebook.edit_cell(0, 'print("Hello, world!")') # Edit a cell
notebook.save() # Save the changes
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 notebookllm-1.1.0.tar.gz.
File metadata
- Download URL: notebookllm-1.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d34880039602732dfad03ef776dfc4d88ae5e2d330828e04e8561b121dc4d3c
|
|
| MD5 |
a5ca719940dde4ab41579ac75c8c53ce
|
|
| BLAKE2b-256 |
f58c6b5b0ecda62909dcd11315a98db60a27615e2766870bf3204c2996e68369
|
File details
Details for the file notebookllm-1.1.0-py3-none-any.whl.
File metadata
- Download URL: notebookllm-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d573878ae22b1a4680e1ff3c2790e85c17f27744b91d80b4ed150da473ba8282
|
|
| MD5 |
09e3aa2605eb2b02fb176e7ae2c74f21
|
|
| BLAKE2b-256 |
a162d312cce31c88037515f499d7bc155ec8728ca0cd9cace4abfaf091c8f583
|