Skip to content

File formats

igaurab edited this page Nov 18, 2026 · 3 revisions

gpython reads and writes four formats. It writes a file back in the format that it had.

Format How gpython knows it Cell borders are stored
Plain .py script No # %% lines, not marimo Outside the file, in ~/.gpython/cells
.py with # %% cells The file has # %% lines In the file
marimo notebook import marimo and @app.cell functions In the file
Jupyter notebook The .ipynb extension In the file

__file__ and the working folder of the kernel are those of the notebook. This is the same as when you run the file as a script.

Plain .py scripts

  • gpython divides the script into cells at top-level statements.
  • gpython saves the file without # %% lines. Thus the script stays an ordinary script.
  • A new notebook that you save as .py is also a plain script.
  • A top-level """text""" string is a markdown cell.

gpython keeps this data outside the file, in ~/.gpython/cells:

  • Where each cell starts and ends.
  • Which cells are markdown and which cells have hidden code.
  • The last outputs, the run number and the run time of each code cell.

When you open the file again, the cells and their outputs come back. More details are in Configuration.

When a different program changed the file

An editor, git or an agent can change the file while gpython does not have it open. gpython compares the file with what it last saved, and keeps what is still there:

What changed What gpython shows
Nothing in a cell The cell and its output, as before
A line in a cell The same cell with the new code. Its old output stays, and the cell is marked stale
A cell that uses the names of a changed cell Its old output stays, and the cell is marked stale
New code between cells or at the end New cells
New lines directly after a cell, with no empty line They go into that cell
A cell that was deleted The cell is gone. The other cells stay
All the lines of a cell New cells, divided as for a script that gpython opens for the first time

A stale cell needs a run. Press f4 to run all stale cells. gpython does not remove an old output until you run the cell or use :clear.

This is also for the outputs of .py files with # %% lines and of marimo notebooks.

.py with # %% cells

This is the format of VS Code and Jupytext.

Line Meaning
# %% A code cell starts
# %% [markdown] A markdown cell starts. Its lines start with #

A file that has # %% lines keeps them when you save.

To remove the # %% lines, use :clean. gpython saves the file as a plain script and keeps where the cells are in ~/.gpython/cells. The outputs stay. Markdown cells become """text""" strings. :set nomarkers does this for each .py file that you save, and :set markers stops it.

To get this format from a plain script, use :copy all metadata. It copies the notebook to the clipboard with the # %% lines.

marimo notebooks

gpython opens the @app.cell functions as cells. If you change nothing, gpython saves the file byte for byte the same.

Item Kept
Cell names Yes
hide_code=True Yes. Such cells open with hidden code. h in cell mode shows it
mo.md(...) cells Yes. gpython shows them as markdown and does not run them
Other decorator arguments No
Comments after the return of a cell No

In the kernel, a small marimo substitute supplies mo.md, mo.Html, mo.hstack, mo.vstack and placeholders for mo.ui. Thus these notebooks run.

Jupyter notebooks

Item On open On save
Code and markdown cells Loaded Saved
Outputs Loaded Saved with the current outputs
Run numbers Loaded Saved
Notebook metadata Kept Kept

Copy a notebook as text

Command What goes to the clipboard
:copy This cell
:copy all The notebook as code. Markdown cells become comments
:copy all metadata The same, with the # %% lines

:clean changes the file itself: it saves the .py file without its # %% lines.

Clone this wiki locally