Store Jupyter notebooks as .py files in Git so pull requests show clean, readable diffs instead of JSON noise
Edit a notebook's code in your IDE, then reload it in Jupyter to see the changes reflected immediately as a notebook
Keep notebooks in two synced formats.ipynb for saved outputs and .py for clean version control, updated together on every save
Jupytext is a tool that lets you save Jupyter notebooks as plain text files instead of the default JSON format. Jupyter notebooks are a popular way for data scientists and researchers to mix code, output, and explanatory text in a single document. The standard notebook file format stores everything as a large JSON blob, which creates messy and hard-to-read version control diffs. Jupytext converts notebooks into regular Python, Julia, R, or Markdown files that are much easier to track with Git. The most common format Jupytext uses is called the percent format. In this format, a notebook saved as a .py file uses comment markers like # %% to indicate where each cell begins, and # %% [markdown] for text cells. The result is a normal Python script that any code editor can open and modify. You can edit the Python file in your IDE, then reload it in Jupyter to see the changes reflected as a notebook. Jupytext also supports paired notebooks, where a single notebook is kept in two forms at the same time: the standard .ipynb file (which stores outputs like charts and printed results) and a text file such as a .py script (which stores only the code and text, cleanly). When you save in Jupyter, both files are updated together. When a collaborator pulls the text version from a repository and opens it in Jupyter, Jupyter rebuilds the notebook from the text file, and any previously saved outputs load from the .ipynb file if it exists. A command-line tool is included for converting between formats, syncing paired files, and piping notebook code through formatting tools like Black. A JupyterLab extension adds right-click menu options for pairing notebooks and opening .py or .md files directly as notebooks. The main practical benefit is cleaner collaboration on notebooks through Git: diffs show only the lines of code that actually changed, merge conflicts are manageable, and code review tools work as they would on any plain script.
← mwouts on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.