Using Jupyter Magics in Plain Python Files for Easier AI-Assisted Coding

Prev Next

Start a VS Code server.

Once it’s started, open the Extensions pane.

  1. Update extensions such as python and the python debugger

  2. Click ‘reload window’ to refresh the page

Open a terminal, and setup the environment:

# create a project directory
mkdir my-project
cd my-project
# install uv and initialize a project
pip install uv
uv init --python 3.12

Add dependencies:

# add ipykernel, and any other depenencies you need
uv add ipykernel seaborn pandas matplotlib numpy

Next open the new project in it’s own window. This will ensure the new .venv is used for the project. Click File —> Open Folder…

Type the path to your project, and click OK.

Add a line to mark the beginning of a cell: # %%

When you click Run Cell a new window will be opened with the result:

This window has options such as Export which will allow you to save the full notebook (.ipynb) that contains the complete code, images, markdown, etc..

This approach is ideal for using AI coding tools such as Cline, because they can more easily edit .py files, saving both time and tokens.

For example, just enable the free Cline Extension, and ask Cline to assist with editing your code.