API Reference

nb4llm.converter.convert_ipynb_to_txt(ipynb_path: str, txt_path: str) None[source]

Convert a Jupyter notebook (.ipynb) to a readable text file (.txt).

This function reads a Jupyter notebook file and writes its content into a text format. Markdown and code cells are converted to fenced blocks, preserving code cell language.

Parameters:
  • ipynb_path (str) – Path to the Jupyter notebook file.

  • txt_path (str) – Path to the output text file.

Return type:

None

Examples

>>> convert_ipynb_to_txt('notebook.ipynb', 'notebook.txt')
# notebook.txt will contain:
#   # notebook.ipynb
#   ```markdown
#   Some markdown
#   ```
#   ```python
#   print('hello')
#   ```

CLI Example

$ nb4llm notebook.ipynb # Output: notebook.txt

nb4llm.converter.convert_txt_to_ipynb(txt_path: str, ipynb_path: str) None[source]

Convert a text file (.txt) in nb4llm format back to a Jupyter notebook (.ipynb).

Parameters:
  • txt_path (str) – Path to the input text file.

  • ipynb_path (str) – Path to the output Jupyter notebook file.

Return type:

None

Examples

>>> convert_txt_to_ipynb('notebook.txt', 'notebook.ipynb')
# notebook.ipynb will be created from the text blocks in notebook.txt

CLI Example

$ nb4llm –reverse notebook.txt # Output: notebook.ipynb

nb4llm.converter.get_fence(cell_source: str, min_length: int = 3) str[source]

Get the fence for a cell source. Ensures the fence is longer than any sequence of backticks in the cell.

cell_sourcestr

The source code or markdown of a cell.

min_lengthint, optional

The minimum length of the fence (default: 3).

str

The fence string (e.g., ‘`' or '``’).

>>> get_fence('Here is some code: ```python

print(1) ```’)

````

CLI interface for nb4llm - Convert Jupyter notebooks to/from text format for LLM processing.

nb4llm.cli.main() None[source]