JupyterPlutoConverter.jl
Another Jupyter notebook to Pluto converter.
By using Pluto's Notebook
and Cell
structs, the core functionality of this package is implemented in around 30 lines of code.
Installation
To install this package, open the Julia REPL and run:
julia> ]add JupyterPlutoConverter
Getting started
This package currently supports one-way conversions from Jupyter to Pluto. A single function jupyter2pluto
is exported:
using JupyterPlutoConverter
# Convert notebook:
jupyter2pluto("notebook.ipynb") # use default output filename "notebook.jl"
jupyter2pluto("notebook.ipynb", "my_pluto_notebook.jl") # use custom output filename
# Convert directory:
jupyter2pluto(".") # convert all Jupyter notebooks in current directory
jupyter2pluto(".", recursive=true) # recursively look through subdirectories
Several keyword arguments can be specified:
fold_md
: If true, Markdown cells are folded, hiding their source. Defaults totrue
.wrap_block
: If true, code cells with multiple lines of code are wrapped inbegin ... end
blocks. Defaults tofalse
.overwrite
: If true, files at the specified output path will be overwritten. Defaults tofalse
.recursive
: If true, applyingjupyter2pluto
to a directory will recursively look for Jupyter notebooks in sub-directories. Defaults tofalse
.verbose
: Toggle verbosity. Defaults totrue
.
Caveats
As the Pluto.jl ⇆ Jupyter conversion notebook summarizes, all automatic conversions from Jupyter to Pluto have caveats:
Pluto is different from Jupyter in many ways - the conversion will not be perfect. Pluto has restrictions on what kind of code you can write (no multiple definitions, for example), and it can be frustrating to start out with a notebook that contains a lot of these 'reactivity errors'.
Try it out, but remember that it might be easier to start the Pluto notebook 'from scratch' and copy code cell-by-cell. Pluto is designed for a different style of writing - this will be difficult to appreciate when you start out with a Jupyter notebook.
Reactivity makes this process more fun than you might think!
Related works
- Pluto.jl ⇆ Jupyter conversion: Observable notebook by Fons. Converts both ways.
- Jupyter2Pluto.jl: Composes strings manually to construct Pluto notebooks. Converts both ways.