Skip to main content

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.

Python 3.9+ License: MIT CI


๐Ÿš€ 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

  1. Fork the repo and create a feature branch.
  2. Make your changes and add tests.
  3. Run pre-commit run --all-files and pytest.
  4. 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


Download files

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

Source Distribution

nb4llm-0.1.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

nb4llm-0.1.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file nb4llm-0.1.2.tar.gz.

File metadata

  • Download URL: nb4llm-0.1.2.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

Hashes for nb4llm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ff3bc97542e4040fb48951a34831f95a418ded80982aee135086f505c09385e2
MD5 6d2909a0f66e9a4bbc6ce565eba96253
BLAKE2b-256 49120d8a58dc7e51e927e21b601583245be7c3ab7744641fb333f5924ee212ab

See more details on using hashes here.

File details

Details for the file nb4llm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nb4llm-0.1.2-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

Hashes for nb4llm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be56c0325e20c7be1fa8764beae5b0c1ca18495071a012a786679086b54e363f
MD5 5db80e0dbedb8efefe085887b54fdffe
BLAKE2b-256 edcfc2a66155ae38e71bd22a6712519695131a5bf77e862c5714d293a8d2742a

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