This notebook contains mostly “raw” cells in reStructuredText format, which are used to auto-generate the …
API Documentation§
-
jupyter_format.
generate_lines
(nb)[source]§ Generator yielding lines to be written to
.jupyter
files.Each of the lines has a line separator at the end, therefore it can e.g. be used in
writelines()
.- Parameters
nb (nbformat.NotebookNode) – A notebook node.
-
jupyter_format.
serialize
(nb)[source]§ Convert a Jupyter notebook to a string in
.jupyter
format.- Parameters
nb (nbformat.NotebookNode) – A notebook node.
- Returns
.jupyter
file content.- Return type
-
jupyter_format.
deserialize
(source)[source]§ Convert
.jupyter
string representation to Jupyter notebook.Lines have to be terminated with
'\n'
(a.k.a. universal newlines mode).If source is an iterable, line terminators may be omitted.
- Parameters
source (str or iterable of str) – Content of
.jupyter
file.- Returns
A notebook node.
- Return type
-
exception
jupyter_format.
ParseError
[source]§ Exception that is thrown on errors during reading.
This reports the line number where the error occured.
Contents Manager§
Exporters for nbconvert
§
-
class
jupyter_format.exporters.
JupyterImportMixin
[source]§ Allow
*.jupyter
files as input to exporters.This is used in all exporters as a “mixin” class.
-
class
jupyter_format.exporters.
JupyterExporter
(**kwargs)[source]§ Convert Jupyter notebooks to
.jupyter
format.
The rest of the exporters are just the ones from nbconvert.exporters, enhanced with the JupyterImportMixin.
Batch Conversion with replace_all
§
Script to recursively replace .ipynb
with .jupyter
files.
Usage:
python3 -m jupyter_format.replace_all --recursive --yes
WARNING: This deletes all original files!
Usage to apply this to the whole history of a Git branch:
git filter-branch --tree-filter "python3 -m jupyter_format.replace_all --recursive --yes"
-
jupyter_format.replace_all.
ipynb_to_jupyter
(path)[source]§ Replace given
.ipynb
file with a.jupyter
file.WARNING: This deletes the original file!
- Parameters
path (os.PathLike or str) – Path to
.ipynb
file.
-
jupyter_format.replace_all.
replace_all_recursive
(start_dir, mapfunction=<class 'map'>)[source]§ Replace all
.ipynb
files recursively.WARNING: This deletes all original files!
- Parameters
path (os.PathLike or str) – Starting directory.
mapfunction –
map()
-like function that can be provided in order to enable parallelization.