Convert Jupyter notebooks to/from text format for LLM processing
Project description
nb4llm
Convert Jupyter notebooks to and from a readable, LLM-friendly text format.
๐ Features
- Convert
.ipynbโ.txt: Extracts markdown and code cells as readable, chunked blocks. - Convert
.txtโ.ipynb: Reconstructs a notebook from the text format. - Language-aware: Preserves code cell language (Python, R, Julia, etc).
- Robust chunking: Handles nested code fences and markdown.
- CLI tool: Easy to use from the command line or scripts.
- Pre-commit, Black, isort, flake8: Modern Python dev workflow.
๐ฆ Installation
pip install -e .
# or, for development:
pip install -e .[dev]
๐ Usage
Convert a notebook to text
nb4llm notebook.ipynb
# Output: notebook.txt
Convert a notebook to a specific text file
nb4llm notebook.ipynb output.txt
Convert text back to a notebook
nb4llm --reverse notebook.txt
# Output: notebook.ipynb
Convert text to a specific notebook file
nb4llm --reverse notebook.txt output.ipynb
Show help
nb4llm --help
๐งโ๐ป Example Text Format
# my_notebook.ipynb
```markdown
Some markdown text
# Some code
print(\"Hello, world!\")
---
## ๐ ๏ธ Development
### **Run tests**
```bash
pytest tests/
Run formatting and linting
pre-commit run --all-files
Type checking
mypy src/
๐งฉ Project Structure
nb4llm/
โโโ src/
โ โโโ nb4llm/
โ โโโ __init__.py
โ โโโ cli.py
โ โโโ converter.py
โโโ tests/
โ โโโ test_cli.py
โ โโโ test_converter.py
โ โโโ conftest.py
โโโ pyproject.toml
โโโ .pre-commit-config.yaml
โโโ .flake8
โโโ README.md
๐ Contributing
- Fork the repo and create a feature branch.
- Make your changes and add tests.
- Run
pre-commit run --all-filesandpytest. - Submit a pull request!
๐ License
MIT License. See LICENSE for details.
Built for robust, LLM-friendly notebook processing.
Let me know if you want this written to your README.md or want to tweak any section!
Contact
name: Amber Malpas github: AmberLee2427 email: malpas.1@osu.edu
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 nb4llm-0.1.3.tar.gz.
File metadata
- Download URL: nb4llm-0.1.3.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62962d1f95cff3ca2d519f352717cb5c8ee9f8fed082adc46eed401fa4539473
|
|
| MD5 |
e47f15437493df16a4f1821aaf88cbaa
|
|
| BLAKE2b-256 |
c2a76321afaa5b3cbcfe144a2827ac0aeec7cfcc7c67dda3548e158631ccce01
|
File details
Details for the file nb4llm-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nb4llm-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e51e3db6154d2982009667aa485e989728c577e6f4671cd9a18cf5f11d3cc32b
|
|
| MD5 |
6aeda0a732464b7801a650d7cbad8f2e
|
|
| BLAKE2b-256 |
878f560f231d35e86054fe452522029030f53cd5218e35e6617767fbd24f55d9
|