> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.conductorquantum.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.conductorquantum.com/_mcp/server.

# stanza.jupyter.utils

Utilities for Jupyter notebook management.

## Module Contents

### Functions

| Name | Description |
|------|-------------|
| [`clean_carriage_returns`](#stanzajupyterutilsclean_carriage_returns) | Remove carriage return artifacts from logged output. |
| [`tail_log`](#stanzajupyterutilstail_log) | Read last N lines from log file. |
| [`format_size`](#stanzajupyterutilsformat_size) | Format bytes to human-readable string. |

### API

```python
stanza.jupyter.utils.clean_carriage_returns(text: str) -> str
```

Remove carriage return artifacts from logged output.

Terminal progress bars use \r to overwrite previous text. When logged to a file,
this creates lines like "old_text\r                              new_text".
We keep only the text after the last \r on each line, which is what would be
visible on a real terminal.

**Parameters:**

<ParamField path="text" type="str">
  Raw text containing carriage return artifacts
</ParamField>

**Returns:**

Cleaned text with only the final visible content from each line


```python
stanza.jupyter.utils.tail_log(
    log_file: pathlib.Path, lines: int = 10
) -> str
```

Read last N lines from log file.

Only reads last 4KB to avoid loading large files into memory.
Splits on \n only to preserve \r for carriage return processing.

**Parameters:**

<ParamField path="log_file" type="pathlib.Path">
  Path to the log file to read
</ParamField>

<ParamField path="lines" type="int" default="10">
  Number of lines to return from the end of the file
</ParamField>

**Returns:**

Last N lines from the log file, or empty string if file doesn't exist


```python
stanza.jupyter.utils.format_size(size_bytes: int) -> str
```

Format bytes to human-readable string.

**Parameters:**

<ParamField path="size_bytes" type="int">
  Size in bytes
</ParamField>

**Returns:**

Human-readable string (e.g., "1.5 KB", "2.3 MB")