|
| 1 | +--- |
| 2 | +pagetitle: Jupytext |
| 3 | +footer: "Jupytext: Text notebooks that you will love, by Marc Wouts. PyData London, June 8, 2025" |
| 4 | +standalone: true |
| 5 | +format: |
| 6 | + revealjs: |
| 7 | + logo: images/jupytext_logo.svg |
| 8 | +--- |
| 9 | + |
| 10 | +{width=80%} |
| 11 | + |
| 12 | +## Jupyter notebooks |
| 13 | + |
| 14 | +Notebooks are amazing for research! And tutorials 😉 |
| 15 | + |
| 16 | +<br> |
| 17 | + |
| 18 | +The `.ipynb` format (JSON) may be a bit verbose but overall it is simple, robust and well documented. |
| 19 | + |
| 20 | +<br> |
| 21 | + |
| 22 | +Jupytext: edit^[or store, convert, synchronize etc.] your notebooks as `.py` files^[many more formats are available, including `.md`] |
| 23 | + |
| 24 | +## Text notebooks |
| 25 | + |
| 26 | +Content is almost what you typed! |
| 27 | + |
| 28 | +```python |
| 29 | +# %% [markdown] |
| 30 | +# This is a markdown cell |
| 31 | + |
| 32 | +# %% |
| 33 | +def f(x): |
| 34 | + return 3*x+1 |
| 35 | +``` |
| 36 | + |
| 37 | +<br> |
| 38 | + |
| 39 | +::: {.callout-tip} |
| 40 | +- Text notebooks can have metadata (but no outputs) |
| 41 | +- Multiline comments also works for Markdown |
| 42 | +::: |
| 43 | + |
| 44 | +## Why text notebooks? |
| 45 | + |
| 46 | +- Well suited for version control |
| 47 | +- Edit and run your notebooks in your IDE |
| 48 | +- Turn your notebooks into libraries |
| 49 | +- Quality assurance: `pre-commit`, `ruff`, typing etc. just work |
| 50 | + |
| 51 | +::: {.callout-tip} |
| 52 | +Text only notebooks are a good fit for |
| 53 | + |
| 54 | +- docs (use the MyST Markdown format) |
| 55 | +- and for tutorials (use the `py:percent` format) |
| 56 | +::: |
| 57 | + |
| 58 | +## Paired notebooks (edit in Jupyter) |
| 59 | + |
| 60 | +In general you want _paired_ notebooks. A paired notebook is made of two files: |
| 61 | + |
| 62 | +- `notebook.ipynb` is your usual notebook |
| 63 | +- `notebook.py` is the text version |
| 64 | + |
| 65 | +<br> |
| 66 | + |
| 67 | +Open either file in Jupyter (they are the same document). |
| 68 | + |
| 69 | +Both files get updated when you save the notebook. |
| 70 | + |
| 71 | +## Paired notebooks (edit in IDE) |
| 72 | + |
| 73 | +Open `notebook.py` in your IDE and edit it. Then re-open the notebook in Jupyter (or reload it), and you will see the edits! |
| 74 | + |
| 75 | +<br> |
| 76 | + |
| 77 | +Input cells are loaded from the `.py` script |
| 78 | + |
| 79 | +Output cells are loaded from the `.ipynb` file. |
| 80 | + |
| 81 | +<br> |
| 82 | + |
| 83 | +::: {.callout-tip} |
| 84 | +To force the synchronization outside of Jupyter, use either `jupytext --sync`, |
| 85 | +our pre-commit hook, or the community-maintained plugins for VIM and VS Code |
| 86 | +::: |
| 87 | + |
| 88 | +## Installation |
| 89 | + |
| 90 | +- `pip install jupytext` or <br>`conda install jupytext -c conda-forge` |
| 91 | +- Restart your Jupyter server |
| 92 | + |
| 93 | +<br> |
| 94 | + |
| 95 | +Now `.py` and `.md` files have a notebook icon, and you get a Jupytext sub-menu in Jupyter 🎉 |
| 96 | + |
| 97 | +## Creating paired notebooks |
| 98 | + |
| 99 | +Pair one notebook using the Jupytext Menu: |
| 100 | + |
| 101 | +{.nostretch width=50% height=50%} |
| 102 | + |
| 103 | +Pair all notebooks in the current and child folders with a `jupytext.toml` file |
| 104 | +containing e.g. `formats="ipynb,py"` |
| 105 | + |
| 106 | +## Creating text notebooks |
| 107 | + |
| 108 | +Create text only notebooks with the _New Text Notebook_ menu. |
| 109 | + |
| 110 | +{.nostretch width=80% height=80%} |
| 111 | + |
| 112 | +Open existing text notebooks with a right click^[run `jupytext-config set-default-viewer python markdown` to open `.py` and `.md` files as notebooks by default] |
| 113 | + |
| 114 | +## Jupytext Stats |
| 115 | + |
| 116 | +- Announced 6 years ago (MIT license) |
| 117 | +- 30+ programming languages supported |
| 118 | +- 98 contributors |
| 119 | +- 6.874 GitHub stars |
| 120 | +- 1.3M downloads/month on PyPI |
| 121 | + |
| 122 | +## Compatibility |
| 123 | + |
| 124 | +Jupytext is compatible with the following stacks |
| 125 | + |
| 126 | +- Jupyter Lab, Notebook, Hub etc. |
| 127 | +- Jupyter Book and especially MyST Markdown |
| 128 | +- VS Code: `# %%` scripts (community extension) |
| 129 | +- Spyder, VIM (plugin), any editor |
| 130 | +- Quarto (`.qmd`) and RStudio (`.Rmd`), Pandoc |
| 131 | +- pre-commit |
0 commit comments