Create advanced Works with: Any AI

From Notebook to Package

Checklist Has example

Move reusable code out of notebooks.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratings…

Plan moving code from a notebook to a package. Notebook description and the functions in it: [NOTEBOOK_FUNCTIONS]. Team size and how the code will be used: [TEAM_USE].

Create a migration plan: identify reusable functions, define inputs and outputs, remove hidden state and global variables, add type hints and docstrings, place code into modules, write tests, and leave the notebook as a thin narrative that imports the package. Provide a folder structure, a minimal packaging configuration described in words, and a checklist for each step. Include a risk list (broken imports, different behaviour) and a way to verify identical results before and after.

Add a short example of before and after code for one function, labelled as an illustration, and a list of signs that code should stay in the notebook. Include a plan for versioning the package inside the team and a rule that results in reports must record the package version used.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

See an example result (fictional data)
Reusable: clean_dates, add_features, load_orders.
Migration steps
1. Remove globals; pass df and config in.
2. Add type hints and docstrings.
3. Move code to package/cleaning.py.
4. Write 6 tests with tiny DataFrames.
5. Notebook imports the package and keeps the narrative.
Before: cell with 80 lines referencing global df.
After: df = clean_dates(df, column="order_date")
Verification: run the old notebook and new one on the same file; compare outputs with assert_frame_equal.
Risks: import errors from relative paths; different default arguments; a notebook that quietly relied on a variable defined in an earlier cell.
Done when: the notebook runs top to bottom in a clean environment and the package tests pass.

Illustrative only, made-up data. Your results will differ and must be reviewed.

Related prompts