Notebook.refactor to utils

From causify-ai/helpers · View interactive version

Notebook.refactor to utils is an AI agent skill from the GitHub repository causify-ai/helpers. Move or add notebook code to a *_utils.py library file

How to use this skill

Skill file

Goal

in py:percent format

Constraints

Scenarios

Scenario 1: Moving Existing Functions to Utils

to utils

Scenario 2: Adding New Code to Utils

corresponding to the notebook

Workflow

Identify or Create the Utils File

Lesson94_Information_Theory_utils.py

Organize Code Structure in Utils File

```python

# #############################################################################

# Cell 1: Visual Bin - Population of Marbles

# #############################################################################

def cell1_draw_bin_with_marbles_interactive(...):

...

def _cell1_helper_function(...):

...

# #############################################################################

# Cell 2: Entropy Calculations

# #############################################################################

def cell2_calculate_entropy(...):

...

```

notebook

notebook

Move or Add Functions

For Moving Functions (Scenario 1):

1. Copy all functions from the notebook to the utils file (without

changing code)

2. Remove the functions from the notebook

3. Update notebook cells to call the utils functions

For Adding Functions (Scenario 2):

1. Implement new code directly in the utils file

2. Create caller code in the notebook that imports and uses the functions

3. Add the code in the appropriate section following the utils file

structure

Update Notebook to Call Utils

```python

import notebook_name_utils as utils

# In code cells:

utils.function_name(...)

```

```python

# Display results of Cell 2 analysis.

utils.cell2_calculate_entropy()

```

Code Reuse

Sync with Jupytext

conventions in # Code Architecture and Responsibility -> `## Utilities vs.

Notebook Responsibilities in .claude/skills/notebook.rules.md`:

```bash

> uvx jupytext --sync <path/to/notebook.py>

```

Conventions

.claude/skills/notebook.rules.md

Verification

corresponding utils function

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.