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.3.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.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

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

Hashes for nb4llm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 62962d1f95cff3ca2d519f352717cb5c8ee9f8fed082adc46eed401fa4539473
MD5 e47f15437493df16a4f1821aaf88cbaa
BLAKE2b-256 c2a76321afaa5b3cbcfe144a2827ac0aeec7cfcc7c67dda3548e158631ccce01

See more details on using hashes here.

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

Hashes for nb4llm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e51e3db6154d2982009667aa485e989728c577e6f4671cd9a18cf5f11d3cc32b
MD5 6aeda0a732464b7801a650d7cbad8f2e
BLAKE2b-256 878f560f231d35e86054fe452522029030f53cd5218e35e6617767fbd24f55d9

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