Skip to main content

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

PyPI PyPI - Downloads

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 .ipynb files to a simplified plain text (.py, .txt or .r file) format.
  • Convert Python or R (.py, .txt or .r files) to .ipynb files.
  • 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 .ipynb file.

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 .ipynb file.
  • --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 .py file.
  • --output <output_file>: Path to save the .ipynb output. If not provided, the output will be saved to output.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notebookllm-1.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notebookllm-1.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for notebookllm-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7d34880039602732dfad03ef776dfc4d88ae5e2d330828e04e8561b121dc4d3c
MD5 a5ca719940dde4ab41579ac75c8c53ce
BLAKE2b-256 f58c6b5b0ecda62909dcd11315a98db60a27615e2766870bf3204c2996e68369

See more details on using hashes here.

File details

Details for the file notebookllm-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for notebookllm-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d573878ae22b1a4680e1ff3c2790e85c17f27744b91d80b4ed150da473ba8282
MD5 09e3aa2605eb2b02fb176e7ae2c74f21
BLAKE2b-256 a162d312cce31c88037515f499d7bc155ec8728ca0cd9cace4abfaf091c8f583

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page