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. If a different editor changed the file, gpython divides it into cells again. More details are in Configuration.

.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 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

Clone this wiki locally